wjwtea
Last Updated: February 25, 2016
·
12.56K
· robertcuadra
F5644723afd1dff27552b69fc973c110

Get a unix timestamp from bash

One liner to get a unix timestamp from terminal. Useful for times when you need to pass one in as a URL param.

Now:
date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"

A week ago:
date -v-1w -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"

A month from now:
date -v+1m -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"

Say Thanks
Respond

1 Response
Add your response

1987
08404c1bd6ab5fad7db0c149ed38ae59

Does not work for me, date does not accept the -j parameter over here.

Try

date +%s

instead. Works great for me and is much shorter.

over 1 year ago ·
Filed Under