Date

发布时间 2023-12-20 15:47:54作者: anpeiyong

概述

The class <code>Date</code> represents a specific instant in time, with millisecond precision.

Date表示特定的时刻,以ms为单位

 

Prior to JDK1.1, the class <code>Date</code> had two additional functions.
It allowed the interpretation of dates as year, month, day, hour, minute, and second values.
It also allowed the formatting and parsing of date strings.

在JDK1.1之前,Date有2个附加的方法:

将Date解释为年、月、日、时、分、秒值;

将Date string 格式化并解析;


Unfortunately, the API for these functions was not amenable to internationalization.
As of JDK1.1, the <code>Calendar</code> class should be used to convert between dates and time fields and the <code>DateFormat</code> class should be used to format and parse date strings.
The corresponding methods in <code>Date</code> are deprecated.

上述2个方法不符合国际化API;

从JDK1.1开始,应使用Calendar在Date与time字段进行转换,并使用DateFormat格式化&解析Date

 

Although the <code>Date</code> class is intended to reflect coordinated universal time (UTC), it may not do so exactly, depending on the host environment of the Java Virtual Machine.
Nearly all modern operating systems assume that 1day= 24 times 60 times 60 = 86400 seconds in all cases.
In UTC, however, about once every year or two there is an extra second, called a "leap second."

尽管Date旨在反映 UTC(世界协调时间),但它依赖于JVM环境,不能完全反映这点;

然而,在 UTC 中,大约每隔一两年就会有一次额外的秒,称为“闰秒”;

 

Some computer standards are defined in terms of Greenwich mean time (GMT), which is equivalent to universal time (UT).
GMT is the "civil" name for the standard; UT is the "scientific" name for the same standard.
The distinction between UTC and UT is that UTC is based on an atomic clock and UT is based on astronomical observations, which for all practical purposes is an invisibly fine hair to split.
Because the earth's rotation is not uniform (it slows down and speeds up in complicated ways), UT does not always flow uniformly.

一些计算标准 根据GMT(格林威治标准时间),相当于世界时间UT;

GMT 是该标准的 民间名称; UT 是同一标准的 科学名称。
UTC 和 UT 之间的区别在于,UTC 基于原子钟,而 UT 基于天文观测,对于所有实际目的而言,天文观测都是微不足道的。

 

public class Date implements java.io.Serializable, Cloneable, Comparable<java.util.Date>{

        private transient long fastTime;

        // Allocates a <code>Date</code> object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
        // 分配一个Date对象 并 初始化,表示指定的ms数 (从标准的基本时间:1970 年 1 月 1 日 00:00:00 GMT)
        public Date(long date) {
            fastTime = date;
        }

        public Date() {
            this(System.currentTimeMillis());
        }
    }