[英]Java Jdeveloper
When I run the following java code in JDeveloper, I get the wrong output. 当我在JDeveloper中运行以下Java代码时,输出错误。 What can be the reasons for that? 可能是什么原因呢?
System.out.println(TimeZone.getTimeZone("Australia/Sydney").inDaylightTime(new Date()));
System.out.println(TimeZone.getTimeZone("Europe/Moscow").inDaylightTime(new Date()));
I am expecting an output as: true false 我期望输出为:true false
But, I am getting it as: false true 但是,我得到它是:false true
PS: This is working correct for few other time zones like "America/Fort_Wayne" and "Europe/Berlin". PS:这对于其他几个时区(如“ America / Fort_Wayne”和“ Europe / Berlin”)都是正确的。
Since the use of new Date()
is not fully following the principle of How to create a Minimal, Complete, and Verifiable example , here it is: 由于new Date()
的使用并不完全遵循如何创建最小,完整和可验证的示例的原理,因此它是:
public static void main(String[] args) {
Date date = new Date(1444817534489L); // 2015-10-14 10:12:14.489 UTC
printDate(date, "UTC");
printDate(date, "Australia/Sydney");
printDate(date, "Europe/Moscow");
printDate(date, "Europe/Berlin");
printDate(date, "America/Fort_Wayne");
}
private static void printDate(Date date, String timeZoneID) {
TimeZone timeZone = TimeZone.getTimeZone(timeZoneID);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
df.setTimeZone(timeZone);
System.out.printf("%-20s %-30s inDaylightTime: %s%n", timeZoneID + ":",
df.format(date), timeZone.inDaylightTime(date));
}
Output 输出量
UTC: 2015-10-14 10:12:14.489 UTC inDaylightTime: false
Australia/Sydney: 2015-10-14 21:12:14.489 AEDT inDaylightTime: true
Europe/Moscow: 2015-10-14 13:12:14.489 MSK inDaylightTime: false
Europe/Berlin: 2015-10-14 12:12:14.489 CEST inDaylightTime: true
America/Fort_Wayne: 2015-10-14 06:12:14.489 EDT inDaylightTime: true
So, true false
as you expected. 因此,如您所料, true false
。 If you saw different, maybe your date was different, and without printing it, how would you know? 如果您看到的日期不同,也许您的日期是不同的,并且不打印它,您怎么知道?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.