Java 日期 toString 包含时区...为什么?
Java Date toString contains a timezone... Why?
我今天在 VB6 中写了一些代码,它会得到自 1970 年 1 月 1 日以来的毫秒数,然后我可以将值发送到 java 应用程序,该应用程序将像 new Date(Long.parse(milliseconds))
。我知道 Date(Long) 正在寻找的毫秒数是自 GMT 纪元以来的毫秒数。我 运行 使用的机器在美国 CDT。当我得到从毫秒解析的日期的 toString 值时,这是我得到的值:
Tue Aug 11 15:40:50 CDT 2015
CDT 是因为本地计算机时区是 CDT 吗?我只是觉得有点奇怪 Date 的构造函数会假设从 GMT 纪元以来的毫秒数派生的日期将隐含在本地机器时区中,而不是偏移(在这种情况下)-5 小时。
Is the CDT just there because the local machines timezone is CDT?
用于显示目的的时区基于默认时区。
Date中的毫秒是相对于纪元的,它没有自己的时区。
它是从 00:00 1970 年 1 月 1 日格林威治标准时间开始拍摄的,或者如果你更喜欢 17:00 1969 年 12 月 31 日 CDT。
would implicitly be in the local machines timezone
本地时区的使用仅用于显示目的。使用另一个时区或序列化 Date
并将其发送到另一个时区的机器,它将再次使用本地时区。
您可以通过使用正确的格式来使用自定义的日期表示法
阅读此 post,它可能对您有所帮助
Change date format in a Java string
你是对的,它在 toString()
中显示 CDT 因为你的 locale indicates that is the correct timezone for you. The Date
object itself doesn't care about timezones and is a glorified wrapper around the Unix epoch in milliseconds. Generally you should use toString()
for debugging purposes, and use a date formatter 实际向用户显示日期(可选地指定一个明确的时区而不是用户的语言环境)。
Date.toString()
的Javadoc只指定了字符串的格式,实际上并没有说明使用哪个时区。我不会依赖 toString()
在每个 Java.
的实现中总是返回默认值 Locale
我今天在 VB6 中写了一些代码,它会得到自 1970 年 1 月 1 日以来的毫秒数,然后我可以将值发送到 java 应用程序,该应用程序将像 new Date(Long.parse(milliseconds))
。我知道 Date(Long) 正在寻找的毫秒数是自 GMT 纪元以来的毫秒数。我 运行 使用的机器在美国 CDT。当我得到从毫秒解析的日期的 toString 值时,这是我得到的值:
Tue Aug 11 15:40:50 CDT 2015
CDT 是因为本地计算机时区是 CDT 吗?我只是觉得有点奇怪 Date 的构造函数会假设从 GMT 纪元以来的毫秒数派生的日期将隐含在本地机器时区中,而不是偏移(在这种情况下)-5 小时。
Is the CDT just there because the local machines timezone is CDT?
用于显示目的的时区基于默认时区。
Date中的毫秒是相对于纪元的,它没有自己的时区。
它是从 00:00 1970 年 1 月 1 日格林威治标准时间开始拍摄的,或者如果你更喜欢 17:00 1969 年 12 月 31 日 CDT。
would implicitly be in the local machines timezone
本地时区的使用仅用于显示目的。使用另一个时区或序列化 Date
并将其发送到另一个时区的机器,它将再次使用本地时区。
您可以通过使用正确的格式来使用自定义的日期表示法
阅读此 post,它可能对您有所帮助 Change date format in a Java string
你是对的,它在 toString()
中显示 CDT 因为你的 locale indicates that is the correct timezone for you. The Date
object itself doesn't care about timezones and is a glorified wrapper around the Unix epoch in milliseconds. Generally you should use toString()
for debugging purposes, and use a date formatter 实际向用户显示日期(可选地指定一个明确的时区而不是用户的语言环境)。
Date.toString()
的Javadoc只指定了字符串的格式,实际上并没有说明使用哪个时区。我不会依赖 toString()
在每个 Java.
Locale