Epoch or Unix timestamp and Date format

Epoch or Unix timestamp and Date format

What is Epoch time ?

Unix time, or POSIX time is also know as Epoch time. Linux/Unix operating systems maintain system time based on some starting time called the Epoch. In Linux/Unix and POSIX systems count time as seconds since midnight Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds. It is widely used not only on Unix-like operating systems but also in many other computing systems. Epoch time is in seconds!!

1] How to get Epoch time ?

* Linux / Ubuntu

root@arun:~# date
Wed Jan 28 23:52:12 IST 2009

root@arun:~# date +%s
1233166934
root@arun:~#

* FreeBSD

root@arun:~# date
Wed Jan 28 11:07:10 IST 2009

root@arun:~# date  +%s
1233169634
root@arun:~#

2] How to convert Epoch time into Date format ?

* Linux / Ubuntu

arunsb@arun:~$ date -d ‘1970-01-01 1233167307 sec’
Wed Jan 28 18:28:27 IST 2009
arunsb@arun:~$

* FreeBSD

arunsb@arun:~# date -r 1233169468
Wed Jan 28 11:04:28 IST 2009
arunsb@arun:~#

3] How to convert Date time into Epoch ?

* Linux / Ubuntu

arunsb@arun:~$ date ; date +%s
Thu Jan 29 00:26:48 IST 2009
1233169008
arunsb@arun:~$ date -d ‘Thu Jan 29 00:26:48 IST 2009’ +%s
1233169008
arunsb@arun:~$ date -d ‘Thu Jan 29 00:26:48 IST 2009’ +%s
1233169008
arunsb@arun:~$

* FreeBSD

root@arun:~#  date -j -f ‘%Y-%m-%d %H:%M:%S %Z’ ‘2009-01-29 00:50:04 PST’ +%s
1233219004

root@arun:~#  date -j -f ‘%Y-%m-%d %H:%M:%S %Z’ ‘2009-01-29 00:50:04 GMT’ +%s
1233190204
root@arun:~#

Thanks,
Arun Bagul

Similar Posts:

2 Replies to “Epoch or Unix timestamp and Date format”

Leave a Reply

Your email address will not be published.