我正在使用Joda time (1.6) 库,它不断返回 DateTime 对象的时区错误,即英国夏令时而不是 GMT。
我的 Windows 工作站(运行 JDK 1.6.0_16)认为它在 GMT 中,如果我从 JDK 日期/时间类中获得默认时区,则它是正确的 (GMT)。我在我们的 Linux 服务器上也有同样的行为。我认为这可能是 Joda 中的时区数据库文件中的错误,所以我用最新的数据库重建了 jar,但没有任何变化。
import java.util.TimeZone;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
public class TimeZoneTest {
public static void main(String[] args) {
DateTimeFormatter timeParser = ISODateTimeFormat.timeParser();
TimeZone timeZone = TimeZone.getDefault();
System.out.println(timeZone.getID()); // "Europe/London"
System.out.println(timeZone.getDisplayName()); // "Greenwich Mean Time"
DateTimeZone defaultTimeZone = DateTimeZone.getDefault();
System.out.println(defaultTimeZone.getID()); //"Europe/London"
System.out.println(defaultTimeZone.getName(0L)); //"British Summer Time"
DateTime currentTime = new DateTime();
DateTimeZone currentZone = currentTime.getZone();
System.out.println(currentZone.getID()); //"Europe/London"
System.out.println(currentZone.getName(0L)); //"British Summer Time"
}
}
通过静态初始化程序进行调试,org.joda.time.DateTimeZone
我看到System.getProperty("user.timezone")
调用"Europe/London"
按预期给出。