美文网首页
二十七、System.currentTimeMillis()与G

二十七、System.currentTimeMillis()与G

作者: 此间有道 | 来源:发表于2020-11-24 13:13 被阅读0次

一、System.currentTimeMillis()函数注释

public final class System {
   /**
     * Returns the current time in milliseconds.  Note that
     * while the unit of time of the return value is a millisecond,
     * the granularity of the value depends on the underlying
     * operating system and may be larger.  For example, many
     * operating systems measure time in units of tens of
     * milliseconds.
     *
     * <p> See the description of the class <code>Date</code> for
     * a discussion of slight discrepancies that may arise between
     * "computer time" and coordinated universal time (UTC).
     *
     * @return  the difference, measured in milliseconds, between
     *          the current time and midnight, January 1, 1970 UTC.
     * @see     java.util.Date
     */
    public static native long currentTimeMillis();
}

二、说明

System.currentTimeMillis()函数获取的是格林威治(GMT)自1970-1-1起始的毫秒数,也称为epoch。

例如:我在东八区的2020-11-24 13:00调用该函数获取的毫秒数为1606194000;
而该毫秒数相对于1970-1-1的时间为2020-11-24 5:00,即GMT时间;

三、结论

  1. 在时间准确的前提下,某一时刻在全球各个时区调用System.currentTimeMillis()的结果是一样的。

相关文章

网友评论

      本文标题:二十七、System.currentTimeMillis()与G

      本文链接:https://www.haomeiwen.com/subject/vpeiiktx.html