我正在尝试使用时间戳来获取今天的时间,时间是11:59,以毫秒为单位。这就是我尝试过的。现在这个代码在一个设备中正常工作,但在另一个设备中没有。它给出了错误
E/test: printstacktrace
java.text.ParseException: Unparseable date: "29/04/2017 11:59:59 PM" (at offset 20)
at java.text.DateFormat.parse(DateFormat.java:579)
at curieo.android.zenmaster.mainfragments.HomeFragment$8.onDataChange(HomeFragment.java:723)
at com.google.android.gms.internal.zzbmz.zza(Unknown Source)
at com.google.android.gms.internal.zzbnz.zzYj(Unknown Source)
at com.google.android.gms.internal.zzboc$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:152)
at android.app.ActivityThread.main(ActivityThread.java:5497)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
String currentDate = questiondateFormat.format(new Date(timeStampLong));
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
Date d = null;
try {
d = sdf.parse(currentDate + " " + "11:59:59 PM");
} catch (ParseException e) {
e.printStackTrace();
}
Calendar c = Calendar.getInstance();
c.setTime(d);
long time = c.getTimeInMillis();
long difference = time - timeStampLong;
countDownTimer.start(difference);