How To Get Current Timestamp In Bash

Bash (linux command line language) provides single command for converting and retrieving dates and times. This command is date.

How To Get Timestamp In Seconds

To get timestamp in seconds you have to use format options and specify, that you want to get timestamp in seconds seconds since 1970-01-01 00:00:00 UTC.


date +"%s"
# 1513277123		

How To Get Timestamp In Milliseconds

There is no direct way how to get timestamp in milliseconds. We have to combine multiple commands. First get current timestamp with nanoseconds, and then convert it to milliseconds.


echo '('`date +"%s.%N"` ' * 1000000)/1' | bc
# 1513277123		
This website uses cookies to ensure you get the best experience on our website. More info