电脑科学电脑编程中,系统时间表示在电脑系统中的时间与日期。通常用系统时钟(system clock)从某个时间起点英语epoch (reference date)的嘀嗒数(number of ticks)。例如,类Unix系统采用世界标准时1970年1月1日00:00:00开始的秒数(不考虑闰秒)作为UNIX时间Windows API使用SYSTEMTIME表示年月日时分秒毫秒;使用FILETIME表示自世界标准时1601年1月1日00:00:00开始的100纳秒为单位的时钟嘀嗒数。

Thumb
Unix命令date

系统时间可以转化为日历时间以适合人去理解。例如Unix时间1000000000对应于日历时间2001年9月9日 01:46:40 UT

获取系统时间

下述均采用格里高利历外推格里高利历英语Proleptic Gregorian calendar。(*)表示依赖于系统实现。

12 10月 2024 01:34:42 UTC

本网页生成时的系统时间
点击此处以刷新时间

操作系统

More information 操作系统, 命令或函数 ...
操作系统 命令或函数 分辨率 时间起点英语epoch (reference date)或范围
Android java.lang.System.currentTimeMillis() 1 ms 起始于1970年1月1日
BIOS (IBM PC) INT 1Ah, AH=00h[1] 54.931 ms
18.204 Hz
当天午夜
INT 1Ah, AH=02h[2] 1 s 当天午夜
INT 1Ah, AH=04h[3] 1 day 1980年1月1日至1999年12月31日

或至2079年12月31日(视系统而定)

CP/M Plus System Control Block:[4]
scb$base+58h, Days since 1 Jan 1978
scb$base+5Ah, Hour (BCD)
scb$base+5Bh, Minute (BCD)
scb$base+5Ch, Second (BCD)
1 s 1978年1月1日只2067年12月
BDOS function 69h (T_GET):[5]
word, Days since 1 January 1978
byte, Hour (BCD)
byte, Minute (BCD)
byte, Second (BCD)
DOS (Microsoft) C:\>DATE
C:\>TIME
10 ms 1980年1月1日至2099年12月31日
INT 21h, AH=2Ch SYSTEM TIME[6]
INT 21h, AH=2Ah SYSTEM DATE[7]
iOS (Apple) CFAbsoluteTimeGetCurrent()[8] < 1 ms 2001年1月1日前后一万年
Mac OS (Apple) CFAbsoluteTimeGetCurrent()[9] < 1 ms[10][note 1] 2001年1月1日前后一万年[10][note 1]
OpenVMS (HP) SYS$GETTIM() 100 ns 1858年11月17日至公元31086年
z/OS (IBM) STCK[11] 2−12 μs
244.14 ps[12]
1900年1月1日至世界时2042年9月17日[13]
Unix, POSIX
(参见C date and time functions)
$date
time()
1 s (*)

1970年1月1日至2038年1月19日
1970年1月1日至公元292277026596年

gettimeofday() 1 μs
clock_gettime() 1 ns
Windows (Microsoft) GetSystemTime() 1 ms 1601年1月1日至公元30828年
GetSystemTimeAsFileTime() 100 ns[14]
Close

程式设计语言与软件

More information 操作系统, 命令或函数 ...
操作系统 命令或函数 分辨率 时间起点英语epoch (reference date)或范围
Ada Ada.Calendar.Clock 100 μs to
20 ms (*)
1901年1月1日至2099年12月31日(*)
AWK systime() 1 s (*)
BASIC, True BASIC DATE, DATE$
TIME, TIME$
1 s (*)
Business BASIC英语Business BASIC DAY, TIM 0.1 s (*)
C (参见C date and time functions) time() 1 s (*)[note 2] (*)[note 2]
C++ std::time()
std::chrono::system_clock::now()
1 s (*)[note 2]
1 ns (C++11, OS dependent)
(*)[note 2]
C# (Microsoft) System.DateTime.Now[15]
System.DateTime.UtcNow[16]
100 ns[17] 0001年1月1日至9999年12月31日
CICS (IBM) ASKTIME 1 ms 1900年1月1日
COBOL FUNCTION CURRENT-DATE 1 s 1601年1月1日
COM COleDateTime 毫秒级[18] 100年1月1日-9999年12月31日
Common Lisp (get-universal-time) 1 s 1900年1月1日
Delphi (Borland) date
time
1 ms
(floating point)
1900年1月1日
Delphi
(Embarcadero Technologies英语Embarcadero Technologies)[19]
System.SysUtils.Time[20] 1 ms 0/0/0000 0:0:0:000至12/31/9999 23:59:59:999 [sic]
System.SysUtils.GetTime[21](alias for System.SysUtils.Time)
System.SysUtils.Date[22] 0/0/0000 0:0:0:000至12/31/9999 0:0:0:000 [sic]
System.DateUtils.Today[23]
System.DateUtils.Tomorrow[24]
System.DateUtils.Yesterday[25]
System.SysUtils.Now[26] 1 s 0/0/0000 0:0:0:000至12/31/9999 23:59:59:000 [sic]
System.SysUtils.DayOfWeek[27] 1 day 1至7
System.SysUtils.CurrentYear[28] 1 year (*)
Emacs Lisp (current-time) 1 μs (*) 1970年1月1日
Excel (Microsoft) date() ? 1900年1月0日[29]
Fortran DATE_AND_TIME
SYSTEM_CLOCK
(*)[30]

[31]

1970年1月1日
CPU_TIME 1 μs
Go time.Now() 1 ns 0001年1月1日
Haskell Time.getClockTime 1 ps (*) 1970年1月1日 (*)
Data.Time.getCurrentTime 1 ps (*) 1858年11月17日(*)
Java (Sun) java.util.Date()
System.currentTimeMillis()
1 ms 1970年1月1日
System.nanoTime()[32] 1 ns 任意的[32]
Clock.systemUTC()[33] 1 ns 任意的[34]
JavaScript new Date()
Date.getTime()
1 ms 1970年1月1日
Matlab now 1 s 0000年1月0日[35]
MUMPS英语MUMPS $H (short for $HOROLOG) 1 s 1840年12月31日
Objective-C [NSDate timeIntervalSinceReferenceDate] < 1 ms[36] 2001年1月1日前后1万年[36]
OCaml Unix.time() 1 s 1 January 1970
Unix.gettimeofday() 1 μs
Extended Pascal GetTimeStamp() 1 s (*)
Turbo Pascal GetTime()
GetDate()
10 ms (*)
Perl time() 1 s 1970年1月1日
Time::HiRes::time[37] 1 μs
PHP time()
mktime()
1 s 1970年1月1日
microtime() 1 μs
Python time.time() 1 μs (*) 1970年1月1日
RPG CURRENT(DATE), %DATE
CURRENT(TIME), %TIME
1 s 0001年1月1日至9999年12月31日
CURRENT(TIMESTAMP), %TIMESTAMP 1 μs
Ruby Time.now()[38] 1 μs (*) 1970年1月1日(Ruby 1.9.2之前最长至2038年1月19日[39]
Smalltalk Time microsecondClock
(VisualWorks)
1 s (ANSI)
1 μs (VisualWorks)
1 s (Squeak)
1901年1月1日(*)
Time totalSeconds
(Squeak)
SystemClock ticksNowSinceSystemClockEpoch
(Chronos)
SQL CURDATE()
CURTIME()
GETDATE()
NOW()
SYSDATE()
3 ms 1753年1月1日至9999年12月31日(*) [note 3][note 4]
60 s 1900年1月1日至2079年6月6日[note 3]
Standard ML Time.now() 1 μs (*) 1970年1月1日(*)
TCL [clock seconds] 1 s 1970年1月1日
[clock milliseconds] 1 ms
[clock microseconds] 1 μs
[clock clicks] 1 μs (*) (*)
Windows PowerShell Get-Date[40][41] 100 ns[17] 0001年1月1日至9999年12月31日
[DateTime]::Now[15]
[DateTime]::UtcNow[16]
Visual Basic .NET (Microsoft) System.DateTime.Now[15]
System.DateTime.UtcNow[16]
100 ns[17] 0001年1月1日至9999年12月31日
Close

不同时间的转换

Windows API提供下述数据结构表示时间:

  • FILETIME:64位元整型值,表示自UTC1601年1月1日开始的每100纳秒的计数。
  • SYSTEMTIME:精度到毫秒。
  • time_t:64位元整型值,表示自UTC1970年1月1日开始的秒的计数。
  • struct tm:精度到秒
  • 高分辨率性能计数器(high-resolution performance counter):每秒的滴答数。

Windows API提供下述函数:

  • 本地时间与系统时间之间的转换:SystemTimeToTzSpecificLocalTime、TzSpecificLocalTimeToSystemTime
  • 系统时间与文件时间的转换:SystemTimeToFileTime、FileTimeToSystemTime
  • 本地时间与文件时间的转换:LocalFileTimeToFileTime、FileTimeToLocalFileTime

注释

参考文献

外部链接

Wikiwand in your browser!

Seamless Wikipedia browsing. On steroids.

Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.

Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.