Posted in Bash Linux
Bash : converting unix timestamp to date
Under Debian or RHEL4 and later, it can be as simple as :
$ date -d @1193144433
Tue Oct 23 15:00:33 CEST 2007
But that command doesn’t work under Redhat EL 3, so you should use the following :
$ date --date "1970-01-01 1193144433 sec" "+%Y-%m-%d %T"
2007-10-23 15:00:33
The output is different though
You can always use the previous command under Ubuntu/RHEL4+ or the simpler :
$ date -d @1193144433 "+%Y-%m-%d %T"
2007-10-23 15:00:33
Converting a date to unix timestamp :
$ date -d "2007-10-23 15:00:23" "+%s"
1193144423
Add "--utc" to the commands if you want to get the UTC time.
Comments
zcharbi
Awesome. Works perfect.
Altair
Just simple and perfect! Exactly what I needed.
Xan
Thanks! That was very helpful. I’m just lazy for reading man’s))
I also prefer
date –d “2008-05-30 11:57:54″ +%s
for back converting
nicod
Merci beaucoup, pile poil ce qu’il me fallait.
misof
thanks
Johan
I want to do this vice versa, I want to convert a e.g.
2007-10-23 15:00:33
to unix timestamp in bash. How to do it?
patrick
Thanks for date -d @Ts
it save me a ton
Sébastien Wains
Johan,
# date -d “2007-10-23 15:00:23″ “+%s”
1193144423
I’m adding this to the post
Leave Comment
Please consider visiting the partners below if you enjoyed this article :If this post saved you time and money, please consider checking my Amazon wishlist.







df
just what I needed! thanks!