Thursday, January 17, 2013

What is UNIX time?



1. What is Unix Time?
  Unix time is total number of seconds measured since  01-Jan-1970 00:00:00.  This time format is used in all the Unix flavors for time computing activities such as dates associated with files/inodes, etc. This date , 1-Jan-1970 00:00:00 is also called epoch date.

2. How to find the Unix time ?
    The date command with %s option :
$ date '+%s'
1357906744
  This number is the total number of seconds elapsed since 01-Jan-1970 till now.

3. Can we calculate the Unix time for a specific date time?
    Yes, using the -d option (available in GNU date ).

To get the timestamp for the date time which is 2 days ago:
$ date -d "2 days ago" '+%s'
1334141505
To get the Unix time for a  specific date : 1-Feb-2012 10 hours 25 mins 15 secs:
$ date -d "2010-02-01 10:25:15 " '+%s'
1265000115
4. Is it possible to calculate the date time from Unix time?
    Yes, it is possible using the -d option.
$ date -d@1334141505
Wed Apr 11 16:21:45 IST 2012
5. What is the Year 2038 problem?
       This Unix time is stored in a structure which is 32 bit. Using a 32 bit structure, time can be provided for a defined period beyond which the number cannot be stored in a 32 bit structure and hence will start overflowing. This period is identified as to be falling on 19 January 2038. Beyond this date, Unix time will start showing past dates due to the negative value resulting in overflow. Hence, after 19 Jan 2038, this time cannot be stored and hence the year 2038 problem. However, systems with 64 bit structure to store the time will not get affected by this.

For detailed references:
1. Wiki Unix Time
2. Why is 1-1-1970 the epoch time?
3. Year 2038 problem
Related Posts Plugin for WordPress, Blogger...

No comments:

Post a Comment