调用“新日期(长)”会导致“ 1970年1月1日01:00:00 CET”? [英] Calling `new Date(long)` results in "Jan 01 01:00:00 CET 1970"?

查看:100
本文介绍了调用“新日期(长)”会导致“ 1970年1月1日01:00:00 CET”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java文档描述了构造函数 Date(long date)使用自1970年1月1日格林威治标准时间00:00:00开始的给定毫秒时间值构造Date对象。

The Java doc describe that the constructor Date(long date) constructs a Date object using the given milliseconds time value since January 1, 1970, 00:00:00 GMT

当我执行新日期(0)时,日期是1月1日 01:00:00 CET 1970

When I did new Date(0), the date is Jan 01 01:00:00 CET 1970

我不知道为什么它以01h开头

I don't know why it begin with 01h

推荐答案

显示1AM,因为您比格林尼治标准时间早一个小时。日期实例只是从1970 GMT 以来的00:00:00以来的毫秒数的计数器。从您开始一个小时以来,纪元实际上是您的时间。

It's show 1AM because you're an hour ahead of GMT. A date instance is simply a counter of the number of milliseconds since 00:00:00 1970 GMT. Since your an hour ahead, when the epoch occurred it was actually 1AM your time.

Date实例只是格式化其toString()方法以使用系统的时区。如果要使用其他区域打印日期,请使用 DateFormat 实例。

The Date instance simply formats its toString() method to use your system's timezone. If you want to print out a date using a different zone, use a DateFormat instance.

这篇关于调用“新日期(长)”会导致“ 1970年1月1日01:00:00 CET”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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