Time (computing)
From Wikipedia, the free encyclopedia
In computer science and computer programming, system time represents a computer system's notion of the passing of time.
System time 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 one-second ticks elapsed since the start of the epoch at 1970-01-01 00:00:00 Z. Microsoft Windows counts the number of 100-nanosecond ticks since 1601-01-01 00:00:00 Z as reckoned in the proleptic Gregorian calendar, but returns the current time to the nearest millisecond.
System time can be converted into calendar time, which is a form more suitable for human comprehension. For example, the Unix system time that is 1,000,000,000 seconds since the beginning of the epoch translates into the calendar time 2001-09-09 01:46:40 UTC. 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.
Closedly 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 instruction 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.
It should be noted that most first-generation PCs did not keep track of dates and times. These included systems that ran the CP/M operating system, the Apple II, and the Commodore PET, among others. The IBM PC was the first widely available personal computer that came equipped with date/time hardware built into the motherboard, and subsequent add-on peripheral boards included real-time clock chips with on-board battery back-up.
[edit] Retrieving System Time
The following tables illustrate methods for retrieving the system time in various operating systems and programming languages.
Operating System | Command or Function | Resolution | Epoch |
---|---|---|---|
DOS (Microsoft) | date time |
1 sec | January 1, 1980 to January 1, 2108 |
INT 1Ah | 54.931 msec 18.204 Hz |
Recycled every 60 min | |
INT 70h | 976.6 msec 1,024 Hz |
Reset on reboot | |
Mac OS (Apple) | GetDateTime() | 1 sec | January 1, 1904 to February 6, 2040 |
OpenVMS (HP) | SYS$GETTIM() | 100 nsec | November 17, 1858 to AD 31086 |
S/390 (IBM) | STCK | 2−12 μsec 244.14 picosec |
January 1, 1900 to September 17, 2042 |
Unix, POSIX | date time() |
1 sec | January 1, 1970 to January 19, 2038 |
gettimeofday() | 1 μsec | January 1, 1970 to January 19, 2038 | |
Windows (Microsoft) | GetSystemTime() | 1 msec | January 1, 1601 to AD 30828 |
GetSystemTimeAsFileTime() | 100 nsec | January 1, 1601 to AD 30828 |
Programming Language | Function | Resolution | Epoch |
---|---|---|---|
AWK | systime() | 1 sec | (*) |
BASIC, True BASIC | DATE, DATE$ TIME, TIME$ |
1 sec | (*) |
C | time() | 1 sec (*) | (*) |
C++ | std::time() | 1 sec (*) | (*) |
CICS (IBM) | ASKTIME | 1 msec | January 1, 1900 |
COBOL | FUNCTION CURRENT-DATE | 1 sec | January 1, 1601 |
FORTRAN | TIME ITIME, IDATE |
1 sec | (*) |
Java | java.util.Date() | 1 msec | January 1, 1970 |
Extended Pascal | GetTimeStamp() | 1 sec | (*) |
Turbo Pascal | GetTime() GetDate() |
10 msec | (*) |
Perl | time() | 1 sec | January 1, 1970 |
PHP | time() mktime() |
1 sec | January 1, 1970 |
microtime() | 1 msec |
Note: Values marked (*) are system-dependent and may differ across implementations.
[edit] See also
[edit] External links
- Critical and Significant Dates, J. R. Stockton (retrieved 2006-09-01)