Jon Skeet 的回答是正确的。
在乔达时代
只是为了好玩,下面是在Java 7中使用第三方库Joda-Time 2.3的源代码解决方案。
详情
DateTimeZone 类有一个方法,isStandardOffset。唯一的技巧是该方法需要很长时间,支持 DateTime 实例的毫秒数,可通过调用 DateTime class‘ superclass‘ (BaseDateTime) 方法 getMillis 访问。
示例源代码
// © 2013 Basil Bourque. This source code may be used freely forever by anyone taking full responsibility for doing so.
org.joda.time.DateTimeZone losAngelesTimeZone = org.joda.time.DateTimeZone.forID("America/Los_Angeles");
org.joda.time.DateTime theSecondAt6PM = new org.joda.time.DateTime( 2013, 11, 2, 18, 0, losAngelesTimeZone ) ;
org.joda.time.DateTime theThirdAt6PM = new org.joda.time.DateTime( 2013, 11, 3, 18, 0, losAngelesTimeZone ) ; // Day when DST ends.
System.out.println("This datetime 'theSecondAt6PM': " + theSecondAt6PM + " is in DST: " + losAngelesTimeZone.isStandardOffset(theSecondAt6PM.getMillis()));
System.out.println("This datetime 'theThirdAt6PM': " + theThirdAt6PM + " is in DST: " + losAngelesTimeZone.isStandardOffset(theThirdAt6PM.getMillis()));
运行时,注意与 UTC 的偏移量差异(-7 与 -8)……
This datetime 'theSecondAt6PM': 2013-11-02T18:00:00.000-07:00 is in DST: false
This datetime 'theThirdAt6PM': 2013-11-03T18:00:00.000-08:00 is in DST: true
关于 Joda-Time…
// Joda-Time - The popular alternative to Sun/Oracle's notoriously bad date, time, and calendar classes bundled with Java 7 and earlier.
// http://www.joda.org/joda-time/
// Joda-Time will become outmoded by the JSR 310 Date and Time API introduced in Java 8.
// JSR 310 was inspired by Joda-Time but is not directly based on it.
// http://jcp.org/en/jsr/detail?id=310
// By default, Joda-Time produces strings in the standard ISO 8601 format.
// https://en.wikipedia.org/wiki/ISO_8601
// About Daylight Saving Time (DST): https://en.wikipedia.org/wiki/Daylight_saving_time
// Time Zone list: http://joda-time.sourceforge.net/timezones.html