一、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时间;
三、结论
- 在时间准确的前提下,某一时刻在全球各个时区调用System.currentTimeMillis()的结果是一样的。
网友评论