Jump to content

Time t: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Reverted edits by 70.112.24.77 to last revision by Qwertyus (HG)
Updated to a more accurate name indicative of Unix enthusiasts
Tag: repeating characters
Line 50: Line 50:
{{Refimprovesect|date=July 2007}}
{{Refimprovesect|date=July 2007}}


Unix enthusiasts have a history of holding '''time_t parties''' to celebrate significant values of the Unix time number.<ref>{{cite web |url=http://slashdot.org/articles/05/03/17/169200.shtml?tid=130 |title=Slashdot {{!}} date +%s Turning 1111111111 |accessdate=2007-07-14 |format= |work= }}
Unix weenies have a history of holding '''time_t parties''' to celebrate significant values of the Unix time number.<ref>{{cite web |url=http://slashdot.org/articles/05/03/17/169200.shtml?tid=130 |title=Slashdot {{!}} date +%s Turning 1111111111 |accessdate=2007-07-14 |format= |work= }}
</ref> 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 numeral system|binary]] numbers are also celebrated, such as +2<sup>30</sup> which occurred at 13:37:04 [[UTC]] on [[January 10]], [[2004]].
</ref> 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 numeral system|binary]] numbers are also celebrated, such as +2<sup>30</sup> which occurred at 13:37:04 [[UTC]] on [[January 10]], [[2004]].



Revision as of 00:05, 16 July 2009

The time_t datatype is a data type in the ISO C library defined for storing system time values. Such values are returned from the standard time() library function. This type is a typedef defined in the standard <time.h> header. ISO C defines time_t as an arithmetic type, but does not specify any particular type, range, resolution, or encoding for it. Also unspecified are the meanings of arithmetic operations applied to time values.

Unix and POSIX-compliant systems implement time_t as an integer or real-floating type [1] (typically a 32- or 64-bit integer) which represents the number of seconds since the start of the Unix epoch: midnight UTC of January 1 1970 (not counting leap seconds). Some systems correctly handle negative time values, while others do not. Systems using a 32-bit time_t type are susceptible to the Year 2038 problem.[2]

In addition to the time() function, ISO C also specifies other functions and types for converting time_t system time values into calendar times and vice versa.

Example

The following C code retrieves the current time, formats it as a string, and writes it to the standard output.

#include <stdio.h>
#include <time.h>

/*
* The result should look something like
* Fri 2008-08-22 15:21:59 WAST
*/

int main(void)
{
    time_t     now;
    struct tm  *ts;
    char       buf[80];

    /* Get the current time */
    now = time(NULL);

    /* Format and print the time, "ddd yyyy-mm-dd hh:mm:ss zzz" */
    ts = localtime(&now);
    strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", ts);
    printf("%s\n", buf);

    return 0;
}

Using GNU date, a given time_t value can be converted into its equivalent calendar date:

$ date -ud@1234567890
Fri Feb 13 23:31:30 UTC 2009

Similarly, using BSD date:

$ date -ur 1234567890
Fri Feb 13 23:31:30 UTC 2009

time_t parties

Unix weenies have a history of holding time_t parties to celebrate significant values of the Unix time number.[3] 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 January 10, 2004.

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 13:37:04 UTC on January 10, 2004, the Unix time number reached 230. It is unknown whether this date was celebrated.
  • At 01:58:31 UTC on March 18, 2005, the Unix time number reached 1,111,111,111.
  • At 03:33:20 UTC on May 18 2033, the Unix time reaches 2,000,000,000 seconds, the second billennium.

See also

References

  1. ^ The Open Group Base Specifications Issue 7 sys/types.h. Retrieved on 2009-02-13.
  2. ^ The Year 2038 problem, Roger M. Wilcox. Retrieved on 2008-05-19.
  3. ^ "Slashdot | date +%s Turning 1111111111". Retrieved 2007-07-14.