System time


In computer science and computer programming, system time represents a computer system's notion of the passage of time. In this sense, time also includes the passing of days on the calendar.
System time is measured by a system clock, which is typically implemented as a simple count of the number of ticks that have transpired since some arbitrary starting date, called the epoch. For example, Unix and POSIX-compliant systems encode system time as the number of seconds elapsed since the start of the Unix epoch at 1 January 1970 00:00:00 UT, with exceptions for leap seconds. Systems that implement the 32-bit and 64-bit versions of the Windows API, such as Windows 9x and Windows NT, provide the system time as both SYSTEMTIME, represented as a year/month/day/hour/minute/second/milliseconds value, and FILETIME, represented as a count of the number of 100-nanosecond ticks since 1 January 1601 00:00:00 UT as reckoned in the proleptic Gregorian calendar.
System time can be converted into calendar time, which is a form more suitable for human comprehension. For example, the Unix system time seconds since the beginning of the epoch translates into the calendar time 9 September 2001 01:46:40 UT. Library subroutines that handle such conversions may also deal with adjustments for time zones, daylight saving time, leap seconds, and the user's locale settings. Library routines are also generally provided that convert calendar times into system times.

Other time measurements

Closely related to system time is process time, which is a count of the total CPU time consumed by an executing process. It may be split into user and system CPU time, representing the time spent executing user code and system kernel code, respectively. Process times are a tally of CPU instructions or clock cycles and generally have no direct correlation to wall time.
File systems keep track of the times that files are created, modified, and/or accessed by storing timestamps in the file control block of each file and directory.

History

Most first-generation personal computers did not keep track of dates and times. These included systems that ran the CP/M operating system, as well as early models of the Apple II, the BBC Micro, and the Commodore PET, among others. Add-on peripheral boards that included real-time clock chips with on-board battery back-up were available for the IBM PC and XT, but the IBM AT was the first widely available PC that came equipped with date/time hardware built into the motherboard. Prior to the widespread availability of computer networks, most personal computer systems that did track system time did so only with respect to local time and did not make allowances for different time zones.
With current technology, most modern computers keep track of local civil time, as do many other household and personal devices such as VCRs, DVRs, cable TV receivers, PDAs, pagers, cell phones, fax machines, telephone answering machines, cameras, camcorders, central air conditioners, and microwave ovens.
Microcontrollers operating within embedded systems do not always have internal hardware to keep track of time. Many such controller systems operate without knowledge of the external time. Those that require such information typically initialize their base time upon rebooting by obtaining the current time from an external source, such as from a time server or external clock, or by prompting the user to manually enter the current time.

Implementation

The system clock is typically implemented as a programmable interval timer that periodically interrupts the CPU, which then starts executing a timer interrupt service routine. This routine typically adds one tick to the system clock and handles other periodic housekeeping tasks before returning to the task the CPU was executing before the interruption.

Retrieving system time

UTC

The Wikipedia system time when this page was last generated.

The following tables illustrate methods for retrieving the system time in various operating systems, programming languages, and applications. Values marked by are system-dependent and may differ across implementations. All dates are given as Gregorian or proleptic Gregorian calendar dates.
Note that the resolution of an implementation's measurement of time does not imply the same precision of such measurements. For example, a system might return the current time as a value measured in microseconds, but actually be capable of discerning individual clock ticks with a frequency of only 100 Hz.

Operating systems

Operating systemCommand or functionResolutionEpoch or range
Androidjava.lang.System.currentTimeMillis1 ms1 January 1970
BIOS INT 1Ah, AH=00h54.9254 ms
18.2065 Hz
Midnight of the current day
BIOS INT 1Ah, AH=02h1 sMidnight of the current day
BIOS INT 1Ah, AH=04h1 day1 January 1980 to 31 December 1999 or 31 December 2079
CP/M PlusSystem Control Block:
scb$base+58h, Days since 1 Jan 1978
scb$base+5Ah, Hour
scb$base+5Bh, Minute
scb$base+5Ch, Second
1 s1 January 1978 to September 2067
CP/M PlusBDOS function 69h :
word, Days since 1 January 1978
byte, Hour
byte, Minute
byte, Second
1 s1 January 1978 to September 2067
DOS DATE
TIME
10 ms1 January 1980 to 31 December 2099
DOS INT 21h, AH=2Ch SYSTEM TIME
INT 21h, AH=2Ah SYSTEM DATE
10 ms1 January 1980 to 31 December 2099
iOS CFAbsoluteTimeGetCurrent< 1 ms1 January 2001 ±10,000 years
macOSCFAbsoluteTimeGetCurrent< 1 ms1 January 2001 ±10,000 years
OpenVMSSYS$GETTIM100 ns17 November 1858 to AD 31,086
z/OSSTCK2−12 μs
244.14 ps
1 January 1900 to 17 September 2042 UT
Unix, POSIX
date
time
1 s
1 January 1970 to 19 January 2038
1 January 1970 to AD 292,277,026,596
Unix, POSIX
1 μs
1 January 1970 to 19 January 2038
1 January 1970 to AD 292,277,026,596
Unix, POSIX
1 ns
1 January 1970 to 19 January 2038
1 January 1970 to AD 292,277,026,596
OS/2DosGetDateTime10 ms1 January 1980 to 31 December 2079
WindowsGetSystemTime1 ms1 January 1601 to 14 September 30,828
WindowsGetSystemTimeAsFileTime100 ns1 January 1601 to 14 September 30,828
WindowsGetSystemTimePreciseAsFileTime100 ns1 January 1601 to 14 September 30,828

Programming languages and applications

Language/ApplicationFunction or variableResolutionEpoch or range
AdaAda.Calendar.Clock100 μs to
20 ms
1 January 1901 to 31 December 2099
AWKsystime1 s
BASIC, True BASICDATE, DATE$
TIME, TIME$
1 s
Business BASICDAY, TIM0.1 s
C time1 s
C++std::time
std::chrono::system_clock::now
1 s
1 ns
C#System.DateTime.Now
System.DateTime.UtcNow
100 ns1 January 0001 to 31 December 9999
CICSASKTIME1 ms1 January 1900
COBOLFUNCTION CURRENT-DATE1 s1 January 1601
Common Lisp1 s1 January 1900
Delphi date
time
1 ms
1 January 1900
Delphi
System.SysUtils.Time1 ms0/0/0000 0:0:0:000 to 12/31/9999 23:59:59:999
Delphi
System.SysUtils.GetTime 1 ms0/0/0000 0:0:0:000 to 12/31/9999 23:59:59:999
Delphi
System.SysUtils.Date1 ms0/0/0000 0:0:0:000 to 12/31/9999 0:0:0:000
Delphi
System.DateUtils.Today1 ms0/0/0000 0:0:0:000 to 12/31/9999 0:0:0:000
Delphi
System.DateUtils.Tomorrow1 ms0/0/0000 0:0:0:000 to 12/31/9999 0:0:0:000
Delphi
System.DateUtils.Yesterday1 ms0/0/0000 0:0:0:000 to 12/31/9999 0:0:0:000
Delphi
System.SysUtils.Now1 s0/0/0000 0:0:0:000 to 12/31/9999 23:59:59:000
Delphi
System.SysUtils.DayOfWeek1 day1 to 7
Delphi
System.SysUtils.CurrentYear1 year
Emacs Lisp1 μs 1 January 1970
Erlang, OS dependent, e.g. on Linux 1ns1 January 1970
Exceldate?0 January 1900
FortranDATE_AND_TIME
SYSTEM_CLOCK
1 January 1970
FortranCPU_TIME1 μs1 January 1970
Gotime.Now1 ns1 January 0001
HaskellTime.getClockTime1 ps 1 January 1970
HaskellData.Time.getCurrentTime1 ps 17 November 1858
Javajava.util.Date
System.currentTimeMillis
1 ms1 January 1970
JavaSystem.nanoTime1 nsarbitrary
JavaClock.systemUTC1 nsarbitrary
JavaScript, TypeScript).getTime
Date.now
1 ms1 January 1970
Matlabnow1 s0 January 0000
MUMPS$H 1 s31 December 1840
LabVIEWTick Count1 ms00:00:00.000 1 January 1904
LabVIEWGet Date/Time in Seconds1 ms00:00:00.000 1 January 1904
Objective-C< 1 ms1 January 2001 ±10,000 Years
OCamlUnix.time1 s1 January 1970
OCamlUnix.gettimeofday1 μs1 January 1970
Extended PascalGetTimeStamp1 s
Turbo PascalGetTime
GetDate
10 ms
Perltime1 s1 January 1970
PerlTime::HiRes::time1 μs1 January 1970
PHPtime
mktime
1 s1 January 1970
PHPmicrotime1 μs1 January 1970
PureBasicDate1 s1 January 1970 to 19 January 2038
Pythondatetime.now.timestamp1 μs 1 January 1970
RPGCURRENT, %DATE
CURRENT, %TIME
1 s1 January 0001 to 31 December 9999
RPGCURRENT, %TIMESTAMP1 μs1 January 0001 to 31 December 9999
RubyTime.now1 μs 1 January 1970
SmalltalkTime microsecondClock
1 s
1 μs
1 s
1 January 1901
SmalltalkTime totalSeconds
1 s
1 μs
1 s
1 January 1901
SmalltalkSystemClock ticksNowSinceSystemClockEpoch
1 s
1 μs
1 s
1 January 1901
SQLCURDATE or CURRENT DATE
CURTIME or CURRENT TIME
GETDATE
NOW or CURRENT TIMESTAMP
SYSDATE
3 ms1 January 1753 to 31 December 9999
SQLCURDATE or CURRENT DATE
CURTIME or CURRENT TIME
GETDATE
NOW or CURRENT TIMESTAMP
SYSDATE
60 s1 January 1900 to 6 June 2079
Standard MLTime.now1 μs 1 January 1970
TCL1 s1 January 1970
TCL1 ms1 January 1970
TCL1 μs1 January 1970
TCL1 μs
Windows PowerShellGet-Date100 ns1 January 0001 to 31 December 9999
Windows PowerShell::Now
::UtcNow
100 ns1 January 0001 to 31 December 9999
Visual Basic.NETSystem.DateTime.Now
System.DateTime.UtcNow
100 ns1 January 0001 to 31 December 9999