Last Updated: February 25, 2016
· aaronott

Simple date conversion from the commandline

Having to work with timestamps can be tough when you need to find out what the string of numbers actually mean for troubleshooting purposes. Normally I would take the number and find a timestamp converter to help me, but then I found that you can use the date command built into Linux.

Let's say that you have the following int that represents a timestamp 1352348312 and you need to know what that timestamp represents. You can do this with the following:

date -d @1352348312

and you'd know that this was Wed Nov 7 21:18:32 MST 2012.

That's great, but what if you needed to know the current timestamp in order to use it in a query? You can do that with the following:

date "+%s"

which would return 1352348312

There are many other cool things that can be done with the date command.

Incidentally, if you are on a Mac and you want to convert a timestamp the format is slightly different.

date -r 1352348312