Press "Enter" to skip to content

epoch examples

Just a few examples for using epoch time for scripts for you to use and abuse:

[code language=”bash”]current_epoch=$(date +%s)[/code]

To find what the epoch time will be on a given date/time:
[code language=”bash”]target_epoch=$(date -d ’01/01/2010 12:00′ +%s)[/code]

How about sleep until:
[code language=”bash”]sleep_seconds=$(( $target_epoch – $current_epoch ))
sleep $sleep_seconds[/code]

To convert unix timestamp to date/time stamp:
[code language=”bash”]date -d @1334998800[/code]

To convert date/time stamp to unix timestamp:
[code language=”bash”]date -d "2013/05/09 23:00:00" "+%s"[/code]