Unix time

Unix time[a] is a date and time representation widely used in computing. It measures time by the number of non-leap seconds that have elapsed since 00:00:00 UTC on 1 January 1970, the Unix epoch. For example, at midnight on January 1 2010, Unix time was 1262304000.
Unix time originated as the system time of Unix operating systems. It has come to be widely used in other computer operating systems, file systems, programming languages, and databases. In modern computing, values are sometimes stored with higher granularity, such as microseconds or nanoseconds.
Remove everything And new open everything
History
This section needs additional citations for verification. (September 2019) |
The earliest versions of Unix time had a 32-bit integer incrementing at a rate of 60 Hz, which was the rate of the system clock on the hardware of the early Unix systems. Timestamps stored this way could only represent a range of a little over two and a quarter years. The epoch being counted from was changed with Unix releases to prevent overflow, with midnight on 1 January 1971 and 1 January 1972 both being used as epochs during Unix's early development. Early definitions of Unix time also lacked timezones.[5][6]
The current epoch of 1 January 1970 00:00:00 UTC was selected arbitrarily by Unix engineers because it was considered a convenient date to work with. The precision was changed to count in seconds in order to avoid short-term overflow.[1]
When POSIX.1 was written, the question arose of how to precisely define time_t
in the face of leap seconds. The POSIX committee considered whether Unix time should remain, as intended, a linear count of seconds since the epoch, at the expense of complexity in conversions with civil time or a representation of civil time, at the expense of inconsistency around leap seconds. Computer clocks of the era were not sufficiently precisely set to form a precedent one way or the other.
The POSIX committee was swayed by arguments against complexity in the library functions,[citation needed] and firmly defined the Unix time in a simple manner in terms of the elements of UTC time. This definition was so simple that it did not even encompass the entire leap year rule of the Gregorian calendar, and would make 2100 a leap year.
The 2001 edition of POSIX.1 rectified the faulty leap year rule in the definition of Unix time, but retained the essential definition of Unix time as an encoding of UTC rather than a linear time scale. Since the mid-1990s, computer clocks have been routinely set with sufficient precision for this to matter, and they have most commonly been set using the UTC-based definition of Unix time. This has resulted in considerable complexity in Unix implementations, and in the Network Time Protocol, to execute steps in the Unix time number whenever leap seconds occur.[citation needed]
Usage
Unix time is widely adopted in computing beyond its original application as the system time for Unix. Unix time is available in almost all system programming APIs, including those provided by both Unix-based and non-Unix operating systems. Almost all modern programming languages provide APIs for working with Unix time or converting them to another data structure. Unix time is also used as a mechanism for storing timestamps in a number of file systems, file formats, and databases.
The C standard library uses Unix time for all date and time functions, and Unix time is sometimes referred to as time_t, the name of the data type used for timestamps in C and C++. C's Unix time functions are defined as the system time API in the POSIX specification.[7] The C standard library is used extensively in all modern desktop operating systems, including Microsoft Windows and Unix-like systems such as macOS and Linux, where it is a standard programming interface.[8][9][10]
iOS provides a Swift API which defaults to using an epoch of 1 January 2001 but can also be used with Unix timestamps.[11] Android uses Unix time alongside a timezone for its system time API.[12]
Windows does not use Unix time for storing time internally but does use it in system APIs, which are provided in C++ and implement the C standard library specification.[8] Unix time is used in the PE format for Windows executables.[13]
Unix time is typically available in major programming languages and is widely used in desktop, mobile, and web application programming. Java provides an Instant object which holds a Unix timestamp in both seconds and nanoseconds.[14] Python provides a time library which uses Unix time.[15] JavaScript provides a Date library which provides and stores timestamps in milliseconds since the Unix epoch and is implemented in all modern desktop and mobile web browsers as well as in JavaScript server environments like Node.js.[16]
Filesystems designed for use with Unix-based operating systems tend to use Unix time. APFS, the file system used by default across all Apple devices, and ext4, which is widely used on Linux and Android devices, both use Unix time in nanoseconds for file timestamps.[17][18] Several archive file formats can store timestamps in Unix time, including RAR and tar.[19][20] Unix time is also commonly used to store timestamps in databases, including in MySQL and PostgreSQL.[21][22]
Limitations
Unix time was designed to encode calendar dates and times in a compact manner intended for use by computers internally. It is not intended to be easily read by humans or to store timezone-dependent values. It is also limited by default to representing time in seconds, making it unsuited for use when a more precise measurement of time is needed, such as when measuring the execution time of programs.[23]
Range of representable times

Unix time by design does not require a specific size for the storage, but most common implementations of Unix time use a signed integer with the same size as the word size of the underlying hardware. As the majority of modern computers are 32-bit or 64-bit, and a large number of programs are still written in 32-bit compatibility mode, this means that many programs using Unix time are using signed 32-bit integer fields. The maximum value of a signed 32-bit integer is 231 − 1, and the minimum value is −231, making it impossible to represent dates before 13 December 1901 (at 20:45:52 UTC) or after 19 January 2038 (at 03:14:07 UTC). The early cutoff can have an impact on databases that are storing historical information; in some databases where 32-bit Unix time is used for timestamps, it may be necessary to store time in a different form of field, such as a string, to represent dates before 1901. The late cutoff is known as the Year 2038 problem and has the potential to cause issues as the date approaches, as dates beyond the 2038 cutoff would wrap back around to the start of the representable range in 1901.[23]: 60
Date range cutoffs are not an issue with 64-bit representations of Unix time, as the effective range of dates representable with Unix time stored in a signed 64-bit integer is over 584 billion years, or 292 billion years in either direction of the 1970 epoch.[23]: 60-61 [24]
Alternatives
Unix time is not the only standard for time that counts away from an epoch. On Windows, the FILETIME
type stores time as a count of 100-nanosecond intervals that have elapsed since 0:00 GMT on 1 January 1601.[25] Windows epoch time is used to store timestamps for files[26] and in protocols such as the Active Directory Time Service[27] and Server Message Block.
The Network Time Protocol used to coordinate time between computers uses an epoch of 1 January 1900, counted in an unsigned 32-bit integer for seconds and another unsigned 32-bit integer for fractional seconds, which rolls over every 232 seconds (about once every 136 years).[28]
Many applications and programming languages provide methods for storing time with an explicit timezone.[29] There are also a number of time format standards which exist to be readable by both humans and computers, such as ISO 8601.
Notable events in Unix time
Unix enthusiasts have a history of holding "time_t parties" (pronounced "time tea parties") to celebrate significant values of the Unix time number.[30][31] These are directly analogous to the new year celebrations that occur at the change of year in many calendars. As the use of Unix time has spread, so has the practice of celebrating its milestones. Usually it is time values that are round numbers in decimal that are celebrated, following the Unix convention of viewing time_t
values in decimal. Among some groups round binary numbers are also celebrated, such as +230 which occurred at 13:37:04 UTC on Saturday, 10 January 2004.[citation needed]
The events that these celebrate are typically described as "N seconds since the Unix epoch", but this is inaccurate; as discussed above, due to the handling of leap seconds in Unix time the number of seconds elapsed since the Unix epoch is slightly greater than the Unix time number for times later than the epoch.
- At 18:36:57 UTC on Wednesday, 17 October 1973, the first appearance of the date in ISO 8601 format[b] (1973-10-17) within the digits of Unix time (119731017) took place.
- At 01:46:40 UTC on Sunday, 9 September 2001, the Unix billennium (Unix time number 1000000000) was celebrated.[32] The name billennium is a portmanteau of billion and millennium.[33][34] Some programs which stored timestamps using a text representation encountered sorting errors, as in a text sort, times after the turnover starting with a 1 digit erroneously sorted before earlier times starting with a 9 digit. Affected programs included the popular Usenet reader KNode and e-mail client KMail, part of the KDE desktop environment. Such bugs were generally cosmetic in nature and quickly fixed once problems became apparent.[citation needed] The problem also affected many Filtrix document-format filters provided with Linux versions of WordPerfect; a patch was created by the user community to solve this problem, since Corel no longer sold or supported that version of the program.[35]
- At 23:31:30 UTC on Friday, 13 February 2009, the decimal representation of Unix time reached 1234567890 seconds.[36] Google celebrated this with a Google Doodle.[37] Parties and other celebrations were held around the world, among various technical subcultures, to celebrate the 1234567890th second.[30][38]
In popular culture
Vernor Vinge's novel A Deepness in the Sky describes a spacefaring trading civilization thousands of years in the future that still uses the Unix epoch. The "programmer-archaeologist" responsible for finding and maintaining usable code in mature computer systems first believes that the epoch refers to the time when man first walked on the Moon, but then realizes that it is "the 0-second of one of humankind's first computer operating systems".[39]
See also
Notes
References
- ^ a b Farhad, Manjoo (8 September 2001). "Unix Tick Tocks to a Billion". Wired. ISSN 1059-1028. Archived from the original on 11 September 2022. Retrieved 16 October 2022.
- ^ "The Open Group Base Specifications Issue 7, Rationale: Base Definitions, section A.4 General Concepts". The Open Group. Archived from the original on 15 November 2017. Retrieved 9 September 2019.
- ^ "The Open Group Base Specifications Issue 7, section 4.16 Seconds Since the Epoch". The Open Group. Archived from the original on 22 December 2017. Retrieved 22 January 2017.
- ^ Matthew, Neil; Stones, Richard (2008). "The Linux Environment". Beginning Linux Programming. Indianapolis, Indiana, US: Wiley. p. 148. ISBN 978-0-470-14762-7.
- ^ Unix Programmer's Manual (PDF) (1st ed.). 3 November 1971. Archived (PDF) from the original on 5 March 2022. Retrieved 28 March 2012.
time returns the time since 00:00:00, Jan. 1, 1971, measured in sixtieths of a second.
- ^ Unix Programmer's Manual (PDF) (3rd ed.). 15 March 1972. Archived (PDF) from the original on 12 February 2023. Retrieved 11 February 2023.
time returns the time since 00:00:00, Jan. 1, 1972, measured in sixtieths of a second...The time is stored in 32 bits. This guarantees a crisis every 2.26 years.
- ^ "The Open Group Technical Standard Base Specifications Issue 7 (2018 edition)". IEEE and The Open Group. Archived from the original on 1 May 2023. Retrieved 1 May 2023.
- ^ a b "time, _time32, _time64". learn.microsoft.net. Microsoft Corporation. 13 February 2023. Archived from the original on 1 May 2023. Retrieved 1 May 2023.
- ^ "The GNU C Library (glibc)". The GNU Operating Sisyem. Free Software Foundation. Archived from the original on 22 April 2016. Retrieved 1 May 2023.
The GNU C Library project provides the core libraries for the GNU system and GNU/Linux systems, as well as many other systems that use Linux as the kernel.
- ^ "Mac OS X Manual Page for localtime(3)". Apple Documentation Archive. Apple Inc. Archived from the original on 22 July 2022. Retrieved 1 May 2023.
- ^ "NSDate". Apple Developer Documentation. Apple Inc. Archived from the original on 1 May 2023. Retrieved 1 May 2023.
- ^ "Time Overview". Android Open Source Project. Google LLC. Archived from the original on 1 May 2023. Retrieved 1 May 2023.
- ^ "PE Format - Win32 apps". learn.microsoft.com. Microsoft Corporation. 24 March 2023. Archived from the original on 29 April 2023. Retrieved 1 May 2023.
- ^ "Instant (Java Platform SE 8 )". docs.oracle.com. Oracle. Archived from the original on 25 November 2016. Retrieved 1 May 2023.
- ^ "time — Time access and conversions", Python documentation, archived from the original on 22 July 2022, retrieved 25 July 2022
- ^ "Date - JavaScript | MDN". developer.mozilla.org. Mozilla. Archived from the original on 21 July 2021. Retrieved 1 May 2023.
- ^ Apple File System Reference (PDF), p. 57, archived (PDF) from the original on 5 November 2022, retrieved 19 October 2022,
This timestamp is represented as the number of nanoseconds since January 1, 1970 at 0:00 UTC, disregarding leap seconds
- ^ "Data Structures and Algorithms". The Linux Kernel documentation. Linux Kernel Organization, Inc. Archived from the original on 1 May 2023. Retrieved 1 May 2023.
- ^ "RAR 5.0 archive format". www.rarlab.com. win.rar GmbH. Archived from the original on 1 May 2023. Retrieved 1 May 2023.
Time is stored in Unix time_t format if this flags [sic] is set and in Windows FILETIME format otherwise
- ^ "Tape Archive (tar) File Format Family". www.loc.gov. Library of Congress. 7 January 2021. Archived from the original on 1 May 2023. Retrieved 1 May 2023.
- ^ "Date and Time Functions", MySQL 8.0 Reference Manual, archived from the original on 19 October 2022, retrieved 19 October 2022
- ^ "8.5. Date/Time Types". PostgreSQL Documentation. The PostgreSQL Global Development Group. 9 February 2023. Archived from the original on 1 May 2023. Retrieved 1 May 2023.
- ^ a b c Rochkind, Mark (2004). Advanced UNIX Programing (2nd ed.). Addison-Wesley. pp. 56–63. ISBN 978-0-13-141154-8.
- ^ Saxena, Ashutosh; Rawat, Sanjay. "IDRBT Working Paper No. 9" (PDF). Archived from the original (PDF) on 13 May 2012.
- ^ "FILETIME (minwinbase.h) - Win32 apps". Microsoft Learn. Microsoft. 2 April 2021. Archived from the original on 10 March 2023. Retrieved 9 March 2023.
- ^ "File Times - Win32 apps". Microsoft Learn. Microsoft. 7 January 2021. Archived from the original on 8 March 2023. Retrieved 9 March 2023.
- ^ "How to convert date/time attributes in Active Directory to standard time format". Microsoft Learn. Microsoft. Archived from the original on 20 October 2022. Retrieved 20 October 2022.
- ^ W. Richard Stevens; Bill Fenner; Andrew M. Rudoff (2004). UNIX Network Programming. Addison-Wesley Professional. pp. 582–. ISBN 978-0-13-141155-5. Archived from the original on 30 March 2019. Retrieved 16 October 2016.
- ^ "datetime — Basic date and time types". Python Standard Library Reference. Python Software Foundation. Archived from the original on 19 October 2022. Retrieved 20 October 2022.
Attributes: year, month, day, hour, minute, second, microsecond, and tzinfo.
- ^ a b Tweney, Dylan (12 February 2009). "Unix Lovers to Party Like It's 1234567890". Wired. Archived from the original on 29 March 2014. Retrieved 12 March 2017.
- ^ "Slashdot | date +%s Turning 1111111111". 17 March 2005. Archived from the original on 12 January 2020. Retrieved 12 January 2020.[unreliable source?]
- ^ "Unix time facts & trivia – Unix Time . Info". Archived from the original on 27 October 2017.
- ^ "UNIX Approaches Ripe Old Age of One Billion". Electromagnetic.net. Archived from the original on 13 April 2013. Retrieved 6 December 2012.
- ^ Neumann, Peter G. (15 October 2001). "The RISKS Digest, Volume 21 Issue 69". The Risks Digest. 21 (69). Archived from the original on 22 October 2015. Retrieved 6 December 2012.
- ^ "Technical Problems". linuxmafia.com. Archived from the original on 11 October 2012. Retrieved 21 August 2017.
- ^ nixCraft. "Humor: On Feb, Friday 13, 2009 Unix time Will Be 1234567890". Cyberciti.biz. Retrieved 5 July 2023.
- ^ "Google 1234567890 Logo". Google Inc. Archived from the original on 11 January 2013. Retrieved 28 January 2013.
- ^ Ahmed, Murad (13 February 2009). "At the third stroke, the Unix time will be 1234567890". The Times. Archived from the original on 14 November 2016. Retrieved 12 January 2020.
- ^ Mashey, John R. (27 December 2004). "Languages, Levels, Libraries, and Longevity". Queue. 2 (9): 32–38. doi:10.1145/1039511.1039532. S2CID 28911378.
External links
- Unix Programmer's Manual, first edition
- Personal account of the POSIX decisions by Landon Curt Noll
- chrono-Compatible Low-Level Date Algorithms – algorithms to convert between Gregorian and Julian dates and the number of days since the start of Unix time