我被这个在 Android 上运行的例子困住了:
SimpleDateFormat sdf = new SimpleDateFormat("dd-mm-yyyy kkmm");
sdf.setTimeZone(TimeZone.getTimeZone(Time.TIMEZONE_UTC));
Date scheduledDateTime = sdf.parse(sms.getScheduledDateTime());
Log.i(TAG, "scheduledDateTime is : " + scheduledDateTime); // scheduledDateTime is : Fri Jan 06 23:58:00 HNEC 2012
Log.i(TAG, "scheduledDateTime milli : " + scheduledDateTime.getTime()); // scheduledDateTime milli : 1325890680000
Calendar calendar = Calendar.getInstance();
Calendar defaultTZCalendar = Calendar.getInstance(TimeZone.getDefault());
Calendar utcTZCalendar = Calendar.getInstance(TimeZone.getTimeZone(Time.TIMEZONE_UTC));
calendar.setTime(scheduledDateTime);
defaultTZCalendar.setTime(scheduledDateTime);
utcTZCalendar.setTime(scheduledDateTime);
Log.i(TAG, "calendar : " + calendar.getTimeInMillis()); // calendar : 1325890680000
Log.i(TAG, "defaultTZCalendar : " + defaultTZCalendar.getTimeInMillis()); // defaultTZCalendar : 1325890680000
Log.i(TAG, "utcTZCalendar : " + utcTZCalendar.getTimeInMillis()); // utcTZCalendar : 1325890680000
现在看看这个:
final long currentTimeMillis = System.currentTimeMillis();
Log.i(TAG, " currentTimeMillis is " + currentTimeMillis); // currentTimeMillis is 1341608182431
Date d = new Date(currentTimeMillis);
Log.i(TAG, " currentTimeMillis is " + d + " ::: d.getTime() = " + d.getTime()); // currentTimeMillis is Fri Jul 06 22:56:22 HAEC 2012 ::: d.getTime() = 1341608182431
两个看起来相同的日期之间怎么可能有 15713902431 这样的差异:Fri Jan 06 23:58:00 HNEC 2012 和 Fri Jul 06 22:56:22 HAEC 2012
顺便提一句,
HNEC 是(法语)欧洲中部正常时间
HAEC 是高级中欧时间(即 DST)
谢谢