gpt4 book ai didi

java - 尴尬的 Java 日期创建行为

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:33:39 30 4
gpt4 key购买 nike

当我尝试创建两个日期时,我刚刚发现了 Java 的 Date 类的一个非常奇怪的行为:

Date startDate = new Date(1282863600000L);
System.out.println(startDate);

Date endDate = new Date(1321919999000L);
System.out.println(endDate);

输出分别为:

Fri Aug 27 00:00:00 BST 2010Mon Nov 21 23:59:59 GMT 2011

有没有人见过这样的东西?两个日期都以相同的方式初始化,但打印时第一个日期显示在 BST 中,后者显示在 GMT 中?

我试图找到对此的解释,但我没有找到。有人可以帮助我吗?

提前致谢!

最佳答案

这是记录在案的行为。

来自 Date.toString() :

Converts this Date object to a String of the form:

 dow mon dd hh:mm:ss zzz yyyy

zzz is the time zone (and may reflect daylight saving time). Standard time zone abbreviations include those recognized by the method parse. If time zone information is not available, then zzz is empty - that is, it consists of no characters at all.

您正在使用使用英国夏令时的语言环境并创建一个应用夏令时规则的日期。这将是当时本地用户期望的日期格式。

关于java - 尴尬的 Java 日期创建行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6186564/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com