Unix time

The Unix time is a simple definition of time, which was developed in 1969 for the Unix operating system and set as the POSIX standard. Before Unix Version 6 Unix clock counted in hundredths of a second, so the era had to be fixed each year. Since Unix Version 6 Unix time counts the seconds elapsed since Thursday, January 1, 1970 00:00 UTC clock, with leap seconds are not counted. This start date is also known as the Epoch (see epoch).

Properties

Conversion

The conversion into a human-readable form, and the use of time zones, daylight savings time and leap years are then taken over by additional functions of the standard library. The representation of the date as seconds since the Unix Epoch is often used because it is much easier to process for computer programs as the "human " date format. In addition, with these values ​​easily periods calculated by simply subtracting the one value from another. Changeover to summer or winter time then no longer play a role. For this reason, this value is also often used as a time stamp. In many modern server applications, the time stamp will continue to play a major role due to these advantages, such as in the field of PHP or MySQL applications in the differentiation and generation of time-related database records. The pre-defined PHP functions date () and mktime () allow here, for example by inserting appropriate function arguments easily convert a timestamp to a human readable date format and vice versa.

Year -2038 problem

Template: Future / In 5 years

Many, but by no means all systems that use the Unix time, store and process the time value as a signed 32 -bit number (integer). Thus, the second area comprises the values ​​-2,147,483,648 to 2,147,483,647. Converted into years, this corresponds to a little over -68 to 68.

On January 19, 2038 at 3:14:08 UTC clock, it is therefore in computer systems which store the Unix time in a signed 32 -bit variable, cause an overflow. The time will be displayed then can no longer be stored in the variable with the 2.147.483.648sten second, which would then come to the year 2038 problem.

Unix time before December 13, 1901 20:45:52 UTC is a signed 32 -bit number can not be displayed, because the time stamp would be smaller than -2147483648.

Modern Unix systems use at least in their 64- bit variant of a signed 64 -bit number, which causes no appreciable restriction of range.

Despite the general trend towards 64 -bit systems, embedded systems based on Unix are currently still almost exclusively 32- bit systems. The apparent trend lately, domestic appliances ( eg router, clock radio, and the like ) to be implemented by embedded systems based on Unix, so runs the risk that these devices from the January 19, 2038 no longer work correctly.

Leap seconds

The Unix time does not include leap seconds. More precisely, during the leap second, the Unix time is going on, and if the UTC time jumps from 23:59:60 to 00:00:00 (after the leap second), then is subtracted from the Unix time one. So From that time again passes through the same range of values ​​as in the second before. The Unix time data in this area are thus ambiguous: they correspond to two times the physical time ( atomic clock ), which differ by one second.

The Epoch, ie the starting point of the Unix time is defined as January 1, 1970 00:00 UTC clock. However, there was at that time the current UTC system not even know it was introduced in its current form until 1972. The timing of the epoch is actually January 1st, 1970 00:00 GMT clock. At this time are recalculated UTC time and UTC time randomly identical. However agree UTC Unix times before 1 January 1972 due to different leap seconds in UTC and GMT are not always exactly the time used GMT time information is the same. Unix time is therefore not suitable for the exact second time representation at any time before 1 January 1972.

In recent years there have been several attempts to add a representation of the leap second for POSIX Unix time definition in the POSIX standardization. However, the discussions on this topic have so far not become a generally accepted result. Many Unix systems implement but next to the Unix time, which is usually tracked the statutory period, in addition a high-resolution time that counts monotonically since the last reboot and therefore is suitable for highly accurate time difference measurements.

Comparison

The Unix time has prevailed in the computer field since the time difference between two events is a subtraction of two integer values ​​. This can be done by advanced arithmetic units in one clock. This is useful for high throughput in special applications such as communication elements ( internet) and file servers (including databases). For the spread of the Internet also a uniform representation of the time to link the file systems of remote computers was necessary. In fact, many of the commercially available network devices are based internally on a fitted Unix system ( Embedded Linux).

Meaningful for human use are often the broken times, in which the usual UTC time is expressed in six figures for year, month, day, hour, minute, second and additional information for time zone and daylight saving time. Even Unix has a conversion of the Unix time in a fractional representation using localtime (). In DOS systems, however, the broken time without time zone information was the standard format and stored on FAT file systems for file timestamps in a compact representation. However, the fractional representation makes calculations consuming. In some cases a time value without an indication of the time zone is useless.

A timeout may be saved as a floating point number. It also very distant time information can be stored, some millions of years away, but then reduced time accuracy. Second accuracy is specified only near the base time (epoch ), which corresponds to the floating-point zero. A resolution of less than one second, for example, is secured with a double value for the next 10,000 years.

Special values

Unix enthusiasts have made ​​it the custom to certain values ​​of the so-called Unix time time_t parties - to hold - like the New Year celebrations of the year. Usually round decimal values ​​, celebrated as 1,000,000,000 or 2,000,000,000. Under some users but also round binary values ​​are celebrated, for example, 230 ( 1.073.741.824 ), which fell on the January 10, 2004 13:37:04 UTC. On 13 February 2009, at 23:31:30 UTC (14 February 2009 00:31:30 CET ) shifted the search engine Google, a special doodle since the Unix time at this moment reached the value 1234567890. Also the Heise Newsticker devoted to this value an article.

The introduction of leap seconds, these values ​​will not display correctly. Nevertheless, these time points are commonly celebrated as "n seconds since the Unix Epoch ".

Unix commands

Some Unix -like systems can be set via command what follows Unix time into the equivalent UTC time to convert ( the behavior of date from the example is not part of the POSIX standard ).

Date -u- d @ UNIX TIME example:

Date -u- d @ 1234567890   Fri February 13 23:31:30 UTC 2009 Conversely, the current number of seconds elapsed since January 1, 1970 on some Unix-/Linux-Systemen by date % s (Show the behavior of date is not also part of the POSIX standard ).

Example Implementation

If you want to calculate the Unix time at a given time, can be accomplished via the following calculation method. The Unix time knows no time zones and uses as input an adjusted time zones time.

Warning: The following code is written in the C programming language, and therefore works with machine-dependent precision. For 32- bit machines can therefore be assumed that the occurrence of the year 2038 problem. Like any sample code it is solely for illustrative purposes and should not be taken into production use without thorough testing.

/ ** Converts structured UTC details in Unix time.   * Parameters and their values ​​- areas:   * - Year [ 1970 .. 2038 ]   * - Month [ 1 .12 ]   * - Tag [ 1 .31 ]   * - Hour [0 .23 ]   * - Minute [0 .59 ]   * - Second [0 .59 ]   * / long unix time (int year, int month, int day,                int hour, int minute, int second ) {    const short tage_seit_jahresanfang = / * days since beginning of the year without days of the current month and leap without * /      0,31,59,90,120,151,181,212,243,273,304,334 { };      long unix_zeit;    long years = year 1970;    switching int years = (( year -1) -1968 ) / 4 - (( year -1) -1900 ) / 100 ( ( year -1) -1600 ) / 400;      unix_zeit = second 60 * minute 60 * 60 * hour      ( tage_seit_jahresanfang [ month - 1] day -1) * 60 * 60 * 24      ( years * 365 scolded years ) * 60 * 60 * 24;      if (( month > 2 ) && ( year % 4 == 0 && ( year % 100 = 0! | | year % 400 == 0 )))      unix_zeit = 60 * 60 * 24; / * Leap year if leap year * /      return unix_zeit; } References

9574
de