The Unix epoch (also known as Unix Time Stamp) is the representation of time as the number of non-leap seconds since 00:00:00 UTC on January 1, 1970, introduced by the Unix operating system, standardised in POSIX, and later adopted by the Java programming language and JavaScript. Because many computers today store the number of seconds as a 32-bit signed integer, the Unix epoch is often said to last 231 seconds, thus “ending” at 03:14:07 Tuesday, January 19, 2038 (UTC).

In POSIX conforming systems, the type time_t is often used to represent times. It is an arithmetic type in the C programming language. There is no requirement that time_t be a 32-bit quantity (it could be a 64-bit integer or a floating point in double format), but most systems define time_t as a signed 32-bit integer, and many application programs may assume it, or may store values in a 32-bit type. A signed 32-bit integer type can represent numbers ranging from -2^31 to 2^31 – 1, that is, -2,147,483,648 to 2,147,483,647. In this format, time_t will run out of positive integers 231-1 seconds (that is 24855 days, 3 hours, 14 minutes and 7 seconds) after the Epoch, in the year 2038, and thus cannot represent times beyond that point. Programs which must handle times beyond the rollover date will need to be changed to accommodate a shift from 32-bit to 64-bit representation, not unlike the Year 2000 problem. Adapting existing programs may be as easy as re-compiling them with header files that declare time_t as a 64-bit integer, but other programs make deep assumptions as to the nature of time_t. In fact, some claim that the expiration of the Unix epoch timeframe may cause more damage than was predicted for the Y2K bug. Compiling time_t as a 64-bit signed integer will allow representation of all points in time 292 billion years before and after 1/1/1970.

To get the current Unix Time Stamp from your unix workstation use “date +%s” from a teminal.

The Perl case

The time() function is used in the Perl programming language to retrieve the Unix epoch. Also, the variable $^T will be set to the epoch value at the time the program began execution.

For measuring time in better granularity than one second, you may use either the Time::HiRes module (from CPAN, and starting from Perl 5.8 part of the standard distribution), or if you have gettimeofday(2), you may be able to use the syscall interface of Perl.

Sometimes you may want to convert the epoch time to real life time measures or the opposite from real life time measures to epoch time, for this you can use the localtime and timelocal subroutines from the standard Time::Local module. It will look like this:

use Time::Local;
$TIME = timelocal($sec, $min, $hours, $mday, $mon, $year);

Sometimes a non-existing time, such as the time of creation of something that does not exist, is indicated as 23:59, 31 Dec 1969.