EN
Bash - current timestamp
9
points
In this short article, we would like to show how to print the current timestamp under Linux using Bash.
Quick solution (run following commands):
date +%s
date "+%Y%m%d%H%M%S"
Example output:
1613387500
20210215120029
Where the timestamp contains: full year, month, day, hours, minutes and seconds.
Note: read this article to see milliseconds time examples.
Other cases
Command Example output Note
date +%s 1613387500 # seconds since 1970-01-01 00:00:00 UTC
date +%s%3N 1613387500137 # %3N is not supported always
date +%s%N 1613387500137650679 # %N is not supported always
date "+%Y%m%d%H%M%S" 20210215120029
date "+%Y%m%d%H%M%S%3N" 20210215120029137
date "+%Y%m%d_%H%M%S" 20210215_120029
date "+%Y%m%d_%H%M%S%3N" 20210215_120029137
date "+%Y_%m_%d_%H_%M_%S" 2021_02_15_12_00_29
date "+%Y_%m_%d_%H_%M_%S_%3N" 2021_02_15_12_00_29_137
date "+%Y.%m.%d %H:%M:%S" 2021.02.15 12:00:29
date "+%Y.%m.%d %H:%M:%S.%3N" 2021.02.15 12:00:29.137
date "+%Y-%m-%d %H:%M:%S" 2021-02-15 12:00:29
date "+%Y-%m-%d %H:%M:%S.%3N" 2021-02-15 12:00:29.137
date "+%Y.%m.%dT%H:%M:%S%z" 2021.02.15T12:00:29+0100