Unix命令date
计算机科学 与计算机编程 中,系统时间 表示在计算机系统中的时间与日期。通常用系统时钟 (system clock)从某个时间起点 的嘀嗒数(number of ticks)。例如,类Unix系统 采用世界标准时 1970年1月1日00:00:00开始的秒数(不考虑闰秒 )作为UNIX时间 。Windows API 使用SYSTEMTIME 表示年月日时分秒毫秒;使用FILETIME 表示自世界标准时1601年1月1日00:00:00开始的100纳秒 为单位的时钟嘀嗒数。
系统时间可以转化为日历时间 以适合人去理解。例如Unix时间1000 000 000 对应于日历时间2001年9月9日 01:46:40 UT 。
获取系统时间
下述均采用格里高利历 与外推格里高利历 。(*)表示依赖于系统实现。
31 1月 2025 04:38:21 UTC
本网页生成时的系统时间 → 点击此处以刷新时间
操作系统
操作系统
命令或函数
分辨率
时间起点 或范围
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]
程序设计语言与软件
操作系统
命令或函数
分辨率
时间起点 或范围
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
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 )[ 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
$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日
不同时间的转换
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
注释
^ 1.0 1.1 苹果开发者文档并没有清晰地说明CFAbsoluteTime/CFTimeInterval的精度和范围,只有在CFRunLoopTimerCreate方法中说明“精度最多在毫秒级”。然而,相似的,可以互换的类型NSTimeInterval (页面存档备份 ,存于互联网档案馆 ) 则列出了精度和范围。
^ 2.0 2.1 2.2 2.3 C标准库 并没有为系统时间值指定特定的分辨率,历法,范围,和数据类型。而C++库则扩展自C库,所以同样跟随C的实现。
^ 3.0 3.1 MySQL的实现
^ Oracle的实现为公元前4712年至公元9999年
参考文献
^ Ralf Brown, "Int 0x1A, AH=0x00" in Ralf Brown's Interrupt List , 2000, http://www.delorie.com/djgpp/doc/rbinter/ix/1A/00.html (页面存档备份 ,存于互联网档案馆 )
^ Ralf Brown, "Int 0x1A, AH=0x02" in Ralf Brown's Interrupt List , 2000, http://www.delorie.com/djgpp/doc/rbinter/ix/1A/02.html (页面存档备份 ,存于互联网档案馆 )
^ Ralf Brown, "Int 0x1A, AH=0x04" in Ralf Brown's Interrupt List , 2000, http://www.delorie.com/djgpp/doc/rbinter/ix/1A/04.html (页面存档备份 ,存于互联网档案馆 )
^ CP/M Plus (CP/M Version 3.0) Operating System Guide (PDF) . [2016-08-14 ] . (原始内容存档 (PDF) 于2016-12-27).
^ BDOS system calls . [2016-08-14 ] . (原始内容存档 于2017-08-19).
^ Ralf Brown, "Int 0x21, AH=0x2c" in Ralf Brown's Interrupt List , 2000, http://www.delorie.com/djgpp/doc/rbinter/ix/21/2C.html (页面存档备份 ,存于互联网档案馆 )
^ Ralf Brown, "Int 0x21, AH=0x2a" in Ralf Brown's Interrupt List , 2000, http://www.delorie.com/djgpp/doc/rbinter/ix/21/2A.html (页面存档备份 ,存于互联网档案馆 )
^ "Time Utilities Reference" (页面存档备份 ,存于互联网档案馆 ) in iOS Developer Library (Apple, 2007).
^ "Time Utilities Reference" (页面存档备份 ,存于互联网档案馆 ) in Mac OS X Developer Library (Apple, 2007).
^ 10.0 10.1 "CFRunLoopTimer Reference" (页面存档备份 ,存于互联网档案馆 ) in Mac OS X Developer Library (Apple, 2007).
^ z/Architecture Principles of Operation (Poughkeepsie, New York:International Business Machines, 2007) 7-187.
^ z/Architecture Principles of Operation , (Poughkeepsie, New York:International Business Machines, 2000) 4-45, 4-46.
^ IBM intends to extend the date range on future systems beyond 2042. z/Architecture Principles of Operation , (Poughkeepsie, New York:International Business Machines, 2007) 1-15, 4-45 to 4-47.
^ 实际上Windows操作系统按照固定时间间隔返回系统时间。对于Windows NT 或 Server 2003是15.625 ms
^ 15.0 15.1 15.2 "DateTime.Now Property" (页面存档备份 ,存于互联网档案馆 ) in MSDN (Microsoft, 2010) last updated July 2010.
^ 16.0 16.1 16.2 "DateTime.UtcNow Property" (页面存档备份 ,存于互联网档案馆 ) in MSDN (Microsoft, 2011)
^ 17.0 17.1 17.2 "DateTime.Ticks Property (页面存档备份 ,存于互联网档案馆 ) in MSDN (Microsoft, 2010) last updated May 2010.
^ COleDateTime采用浮点数表示,整数部分表示日期;小数部分独立表示时分秒,例如6时整总是表示为0.25,不论整数部分的正负。因此1天间隔表示为1.0。1899年12月30日午夜表示为0.0。
^ "Date and Time Support" (页面存档备份 ,存于互联网档案馆 ) in Embarcadero Developer Network (Embarcadero Technologies, 2013)
^ "System.SysUtils.Time" (页面存档备份 ,存于互联网档案馆 ) in Embarcadero Developer Network (Embarcadero Technologies, 2013)
^ "System.SysUtils.GetTime" (页面存档备份 ,存于互联网档案馆 ) in Embarcadero Developer Network (Embarcadero Technologies, 2013)
^ "System.SysUtils.Date" (页面存档备份 ,存于互联网档案馆 ) in Embarcadero Developer Network (Embarcadero Technologies, 2013)
^ "System.DateUtils.Today" (页面存档备份 ,存于互联网档案馆 ) in Embarcadero Developer Network (Embarcadero Technologies, 2013)
^ "System.DateUtils.Tomorrow" (页面存档备份 ,存于互联网档案馆 ) in Embarcadero Developer Network (Embarcadero Technologies, 2013)
^ "System.DateUtils.Yesterday" (页面存档备份 ,存于互联网档案馆 ) in Embarcadero Developer Network (Embarcadero Technologies, 2013)
^ "System.SysUtils.Now" (页面存档备份 ,存于互联网档案馆 ) in Embarcadero Developer Network (Embarcadero Technologies, 2013)
^ "System.SysUtils.DayOfWeek" (页面存档备份 ,存于互联网档案馆 ) in Embarcadero Developer Network (Embarcadero Technologies, 2013)
^ "System.SysUtils.CurrentYear" (页面存档备份 ,存于互联网档案馆 ) in Embarcadero Developer Network (Embarcadero Technologies, 2013)
^ "In the Microsoft Office Spreadsheet Component, the value 0 evaluates to the date December 30, 1899 and the value 1 evaluates to December 31, 1899. ... In Excel, the value 0 evaluates to January 0, 1900 and the value 1 evaluates to January 1, 1900." XL2000: Early Dates on Office Spreadsheet Component Differ from Excel (页面存档备份 ,存于互联网档案馆 ) in (Microsoft Support , 2003).
^ "SYSTEM_CLOCK" (页面存档备份 ,存于互联网档案馆 ), documentation for FORTRAN compiler, Intel Corp., accessed 27 October 2011.
^ SYSTEM_CLOCK — Time function" (页面存档备份 ,存于互联网档案馆 ) in The GNU Fortran Compiler (Free Software Foundation) accessed 27 October 2011.
^ 32.0 32.1 System.nanoTime() method (页面存档备份 ,存于互联网档案馆 ) in Java Platform, Standard Edition 6: API Specification (Oracle, 2011) accessed 27 October 2011.
^ Clock.systemUTC() and other methods (页面存档备份 ,存于互联网档案馆 ) in Java Platform, Standard Edition 8: API Specification (Oracle, 2014) accessed 15 January 2015.
^ JSR-310 Java Time System (页面存档备份 ,存于互联网档案馆 ) in Java Platform, Standard Edition 8: API Specification (Oracle, 2014) accessed 15 January 2015.
^ [1] (页面存档备份 ,存于互联网档案馆 ) Matlab Help
^ 36.0 36.1 "Foundation Data Types Reference" (页面存档备份 ,存于互联网档案馆 ) in Mac OS X Developer Library (Apple, 2011) last modified 6 July 2011, section NSTimeInterval.
^ Douglas Wegscheild, R. Schertler, and Jarkko Hietaniemi, "Time::HiRes" (页面存档备份 ,存于互联网档案馆 ) (CPAN
Comprehensive Perl Archive Network, 2011) accessed 27 October 2011.
^ Time class (页面存档备份 ,存于互联网档案馆 ) in Ruby-Doc.org: Help and documentation for the Ruby programming language (Scottsdale, AZ: James Britt and Neurogami) accessed 27 October 2011.
^ Ruby 1.9.2 Release Notes (页面存档备份 ,存于互联网档案馆 ) in Ruby-Doc.org: Help and documentation for the Ruby programming language (Scottsdale, AZ: James Britt and Neurogami) accessed 27 October 2011.
^ Using the Get-Date Cmdlet . Microsoft TechNet. [11 December 2013] . (原始内容存档 于2017-08-01).
^ Windows PowerShell Tip of the Week – Formatting Dates and Times . Microsoft TechNet. [11 December 2013] . (原始内容存档 于2017-07-31).
外部链接
基本概念 时间单位
取法自然 人為單位 中國古代曆法時間單位 印度古代時間單位 取自物理 理論
天文的年 天文的月 天文的日 天文的時 時間標準 授時與守時
其他
Information related to 系统时间