Tuesday, 4 August 2020

Unix TimeStamp Command

Unix TimeStamp Command, LPI Tutorial and Material, LPI Certification, LPI Exam Prep

What is Unix Timestamp


Unix timestamp is the representation of time as the running total of number of seconds since the unix epoch time on January 1st, 1970. Simply the Unix timestamp is the number of seconds between the particular date and the Unix Epoch.

The unix timestamp become standard in computer systems for tracking the information especially in distributed processing system like hadoop, cloud computing etc.

Here we will see how to convert the unix date to timestamp and unix timestamp to date. We will also see how to generate the unix current timestamp. Let see each one:

1. Unix Current Timestamp


To find the unix current timestamp use the %s option in the date command. The %s option calculates unix timestamp by finding the number of seconds between the current date and unix epoch.

date '+%s'
1327312578

You will get a different output if you run the above date command.

2. Convert Unix Timestamp to Date


You can use the -d option to the date command for converting the unix timestamp to date. Here you have to specify the unix epoch and the timestamp in seconds.

date -d "1970-01-01 956684800 sec GMT"
Tue Apr 25 10:46:40 PDT 2000

3. Convert Unix Date to Timestamp


You have to combine the -d option and the %s option for converting the unix date to timestamp.

date -d "2000-01-01 GMT" '+%s'
946684800

Related Posts

0 comments:

Post a Comment