Last Updated: September 09, 2019
· robertcuadra

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.

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"

1 Response
Add your response

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


date +%s

instead. Works great for me and is much shorter.

over 1 year ago ·