Date.toString()显示什么时区? [英] What time zone does Date.toString() display?

查看:131
本文介绍了Date.toString()显示什么时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,方法 java.util.Date.toString() 显示?由于Java 日期 将给定日期存储在 UTC 中,并且不包含任何明确的时区, Date.toString()只显示主机的默认时区,或 TimeZone.getDefault() ? / p>

By default, what time zone does method java.util.Date.toString() display? Since a Java Date stores a given date in UTC and doesn't contain any explicit time zone, does Date.toString() simply display the default time zone for the host, or TimeZone.getDefault()?

推荐答案

它显示使用 TimeZone.getDefault()将默认为正在运行的操作系统的时区(即主机)。所以在实践中,他们将是同样的事情

It displays using TimeZone.getDefault() which, in turn, will default to the time zone of the operating system it is running on (i.e. the host). So in practice, they will be the same thing

请注意,Java日期不是真正的日期!这是一个即时在开始之前以毫秒的偏移量表示的时间。它仍然包含引用年份 month 等等但都已被弃用的方法。你不应该使用 Date 对象,就像它是一个日期。

Note that a Java date is not really a date! It is an instant in time, represented by a millisecond offset since the beginning of the epoch. It still contains methods which reference year, month etc but these are all deprecated. You should on no account be using a Date object as if it were a date.

使用日历(虽然这可以说比$ Date 更可怕)或像JODA一样的体面的图书馆。

Use a Calendar (although this is arguably even more broken than Date) or a decent library like JODA.

这篇关于Date.toString()显示什么时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆