System time

From Wikipedia, the free encyclopedia
Jump to: navigation, search
"System clock" redirects here. It is not to be confused with Clock generator, Clock signal, or Clock rate.
Unix date command

In computer science and computer programming, system time represents a computer system's notion of the passing 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 ("Unix 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 1000000000 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 timezones, daylight saving time (DST), leap seconds, and the user's locale settings. Library routines are also generally provided that convert calendar times into system times.

Other time measurements[edit]

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 (or inode) of each file and directory.

History[edit]

Most first-generation PCs did not keep track of dates and times. These included systems that ran the CP/M operating system, early models of the Apple II, and the Commodore PET, among others. The IBM AT was the first widely available personal computer that came equipped with date/time hardware built into the motherboard. Add-on peripheral boards included real-time clock chips with on-board battery back-up was also available for the IBM PC and XT. 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 other time zones.

With current technology, all 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.

Implementation[edit]

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. That routine typically adds one tick to the system clock (a simple counter) and handles other periodic housekeeping tasks (preemption, etc.) before returning to whatever the CPU was doing before the interruption.

Retrieving system time[edit]

30 August 2014 11:05:14 UTC

The Wikipedia system time when this page was last generated.
Purge this page, and update this counter.

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 accuracy 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 (10 ms).

Operating systems[edit]

Operating system Command or function Resolution Epoch or range
Android java.lang.System.currentTimeMillis() 1 ms 1 January 1970
BIOS (IBM PC) INT 1Ah, AH=00h[1] 54.931 ms
18.204 Hz
Midnight of the current day
INT 1Ah, AH=02h[2] 1 s Midnight of the current day
INT 1Ah, AH=04h[3] 1 day 1 January 1980 to 31 December 1999 or 31 December 2079 (system dependent)
DOS (Microsoft) C:\>DATE
C:\>TIME
10 ms 1 January 1980 to 31 December 2099
INT 21h, AH=2Ch SYSTEM TIME[4]
INT 21h, AH=2Ah SYSTEM DATE[5]
iOS (Apple) CFAbsoluteTimeGetCurrent()[6] < 1 ms 1 January 2001 ±10,000 years
Mac OS (Apple) CFAbsoluteTimeGetCurrent()[7] < 1 ms[8][note 1] 1 January 2001 ±10,000 years[8][note 1]
OpenVMS (HP) SYS$GETTIM() 100 ns 17 November 1858 to AD 31,086
z/OS (IBM) STCK[9] 2−12 μs
244.14 ps[10]
1 January 1900 to 17 September 2042 UT[11]
Unix, POSIX
(see also C date and time functions)
$date
time()
1 s (*)
1 January 1970 to 19 January 2038
1 January 1970 to AD 292,277,026,596
gettimeofday() 1 μs
clock_gettime() 1 ns
Windows (Microsoft) GetSystemTime() 1 ms 1 January 1601 to AD 30,828
GetSystemTimeAsFileTime() 100 ns

Programming languages and applications[edit]

Language/Application Function or variable Resolution Epoch or range
Ada Ada.Calendar.Clock 100 μs to
20 ms (*)
1 January 1901 to 31 December 2099 (*)
AWK systime() 1 s (*)
BASIC, True BASIC DATE, DATE$
TIME, TIME$
1 s (*)
Business BASIC DAY, TIM 0.1 s (*)
C (see 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[12]
System.DateTime.UtcNow[13]
100 ns[14] 1 January 0001 to 31 December 9999
CICS (IBM) ASKTIME 1 ms 1 January 1900
COBOL FUNCTION CURRENT-DATE 1 s 1 January 1601
Common Lisp (get-universal-time) 1 s 1 January 1900
Delphi (Borland) date
time
1 ms
(floating point)
1 January 1900
Delphi
(Embarcadero Technologies)[15]
System.SysUtils.Time[16] 1 ms 0/0/0000 0:0:0:000 to 12/31/9999 23:59:59:999
System.SysUtils.GetTime[17] (alias for System.SysUtils.Time)
System.SysUtils.Date[18] 0/0/0000 0:0:0:000 to 12/31/9999 0:0:0:000
System.DateUtils.Today[19]
System.DateUtils.Tomorrow[20]
System.DateUtils.Yesterday[21]
System.SysUtils.Now[22] 1 s 0/0/0000 0:0:0:000 to 12/31/9999 23:59:59:000
System.SysUtils.DayOfWeek[23] 1 day 1 to 7
System.SysUtils.CurrentYear[24] 1 year (*)
Emacs Lisp (current-time) 1 μs (*) 1 January 1970
Excel (Microsoft) date()  ? 0 January 1900[25]
Fortran DATE_AND_TIME
SYSTEM_CLOCK
(*)[26]

[27]

1 January 1970
CPU_TIME 1 μs
Go time.Now() 1 ns 1 January 0001
Haskell Time.getClockTime 1 ps (*) 1 January 1970 (*)
Data.Time.getCurrentTime 1 ps (*) 17 November 1858 (*)
Java (Sun) java.util.Date()
System.currentTimeMillis()
1 ms 1 January 1970
System.nanoTime()[28] 1 ns arbitrary[28]
JavaScript new Date()
Date.getTime()
1 ms 1 January 1970
Matlab now 1 s 0 January 0000[29]
MUMPS $H (short for $HOROLOG) 1 s 31 December 1840
Objective-C [NSDate timeIntervalSinceReferenceDate] < 1 ms[30] 1 January 2001 ±10,000 Years[30]
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 1 January 1970
Time::HiRes::time[31] 1 μs
PHP time()
mktime()
1 s 1 January 1970
microtime() 1 μs
Python time.time() 1 μs (*) 1 January 1970
RPG CURRENT(DATE), %DATE
CURRENT(TIME), %TIME
1 s 1 January 0001 to 31 December 9999
CURRENT(TIMESTAMP), %TIMESTAMP 1 μs
Ruby Time.now()[32] 1 μs (*) 1 January 1970 (to 19 January 2038 prior to Ruby 1.9.2[33])
Smalltalk Time microsecondClock
(VisualWorks)
1 s (ANSI)
1 μs (VisualWorks)
1 s (Squeak)
1 January 1901 (*)
Time totalSeconds
(Squeak)
SystemClock ticksNowSinceSystemClockEpoch
(Chronos)
SQL CURDATE()
CURTIME()
GETDATE()
NOW()
SYSDATE()
3 ms 1 January 1753 to 31 December 9999 (*)
60 s 1 January 1900 to 6 June 2079
Standard ML Time.now() 1 μs (*) 1 January 1970 (*)
TCL [clock seconds] 1 s 1 January 1970
[clock milliseconds] 1 ms
[clock microseconds] 1 μs
[clock clicks] 1 μs (*) (*)
Windows PowerShell Get-Date[34][35] 100 ns[14] 1 January 0001 to 31 December 9999
[DateTime]::Now[12]
[DateTime]::UtcNow[13]
Visual Basic .NET (Microsoft) System.DateTime.Now[12]
System.DateTime.UtcNow[13]
100 ns[14] 1 January 0001 to 31 December 9999

See also[edit]

Notes[edit]

  1. ^ a b The Apple Developer Documentation is not clear on the precision & range of CFAbsoluteTime/CFTimeInterval, except in the CFRunLoopTimerCreate documentation which refers to 'sub-millisecond at most' precision. However, the similar type NSTimeInterval appears to be interchangeable, and has the precision and range listed.
  2. ^ a b c d The C standard library does not specify any specific resolution, epoch, range, or datatype for system time values. The C++ library encompasses the C library, so it uses the same system time implementation as C.

References[edit]

  1. ^ Ralf Brown, "Int 0x1A, AH=0x00" in Ralf Brown's Interrupt List, 2000, http://www.delorie.com/djgpp/doc/rbinter/ix/1A/00.html
  2. ^ Ralf Brown, "Int 0x1A, AH=0x02" in Ralf Brown's Interrupt List, 2000, http://www.delorie.com/djgpp/doc/rbinter/ix/1A/02.html
  3. ^ Ralf Brown, "Int 0x1A, AH=0x04" in Ralf Brown's Interrupt List, 2000, http://www.delorie.com/djgpp/doc/rbinter/ix/1A/04.html
  4. ^ Ralf Brown, "Int 0x21, AH=0x2c" in Ralf Brown's Interrupt List, 2000, http://www.delorie.com/djgpp/doc/rbinter/ix/21/2C.html
  5. ^ Ralf Brown, "Int 0x21, AH=0x2a" in Ralf Brown's Interrupt List, 2000, http://www.delorie.com/djgpp/doc/rbinter/ix/21/2A.html
  6. ^ "Time Utilities Reference" in iOS Developer Library (Apple, 2007).
  7. ^ "Time Utilities Reference" in Mac OS X Developer Library (Apple, 2007).
  8. ^ a b "CFRunLoopTimer Reference" in Mac OS X Developer Library (Apple, 2007).
  9. ^ z/Architecture Principles of Operation (Poughkeepsie, New York:International Business Machines, 2007) 7-187.
  10. ^ z/Architecture Principles of Operation, (Poughkeepsie, New York:International Business Machines, 2000) 4-45, 4-46.
  11. ^ 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.
  12. ^ a b c "DateTime.Now Property" in MSDN (Microsoft, 2010) last updated July 2010.
  13. ^ a b c "DateTime.UtcNow Property" in MSDN (Microsoft, 2011)
  14. ^ a b c "DateTime.Ticks Property in MSDN (Microsoft, 2010) last updated May 2010.
  15. ^ "Date and Time Support" in Embarcadero Developer Network (Embarcadero Technologies, 2013)
  16. ^ "System.SysUtils.Time" in Embarcadero Developer Network (Embarcadero Technologies, 2013)
  17. ^ "System.SysUtils.GetTime" in Embarcadero Developer Network (Embarcadero Technologies, 2013)
  18. ^ "System.SysUtils.Date" in Embarcadero Developer Network (Embarcadero Technologies, 2013)
  19. ^ "System.DateUtils.Today" in Embarcadero Developer Network (Embarcadero Technologies, 2013)
  20. ^ "System.DateUtils.Tomorrow" in Embarcadero Developer Network (Embarcadero Technologies, 2013)
  21. ^ "System.DateUtils.Yesterday" in Embarcadero Developer Network (Embarcadero Technologies, 2013)
  22. ^ "System.SysUtils.Now" in Embarcadero Developer Network (Embarcadero Technologies, 2013)
  23. ^ "System.SysUtils.DayOfWeek" in Embarcadero Developer Network (Embarcadero Technologies, 2013)
  24. ^ "System.SysUtils.CurrentYear" in Embarcadero Developer Network (Embarcadero Technologies, 2013)
  25. ^ "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).
  26. ^ "SYSTEM_CLOCK", documentation for FORTRAN compiler, Intel Corp., accessed 27 October 2011.
  27. ^ SYSTEM_CLOCK — Time function" in The GNU Fortran Compiler (Free Software Foundation) accessed 27 October 2011.
  28. ^ a b System.nanoTime() method in Java Platform, Standard Edition 6: API Specification (Oracle, 2011) accessed 27 October 2011.
  29. ^ [1] Matlab Help
  30. ^ a b "Foundation Data Types Reference" in Mac OS X Developer Library (Apple, 2011) last modified 6 July 2011, section NSTimeInterval.
  31. ^ Douglas Wegscheild, R. Schertler, and Jarkko Hietaniemi, "Time::HiRes" (CPAN Comprehensive Perl Archive Network, 2011) accessed 27 October 2011.
  32. ^ Time class in Ruby-Doc.org: Help and documentation for the Ruby programming language (Scottsdale, AZ: James Britt and Neurogami) accessed 27 October 2011.
  33. ^ 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.
  34. ^ "Using the Get-Date Cmdlet". Microsoft TechNet. Retrieved 11 December 2013. 
  35. ^ "Windows PowerShell Tip of the Week – Formatting Dates and Times". Microsoft TechNet. Retrieved 11 December 2013. 

External links[edit]