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):
xxxxxxxxxx
1
date +%s
2
date "+%Y%m%d%H%M%S"
Example output:
xxxxxxxxxx
1
1613387500
2
20210215120029
Where the timestamp contains: full year, month, day, hours, minutes and seconds.
Note: read this article to see milliseconds time examples.
xxxxxxxxxx
1
Command Example output Note
2
3
date +%s 1613387500 # seconds since 1970-01-01 00:00:00 UTC
4
date +%s%3N 1613387500137 # %3N is not supported always
5
date +%s%N 1613387500137650679 # %N is not supported always
6
date "+%Y%m%d%H%M%S" 20210215120029
7
date "+%Y%m%d%H%M%S%3N" 20210215120029137
8
date "+%Y%m%d_%H%M%S" 20210215_120029
9
date "+%Y%m%d_%H%M%S%3N" 20210215_120029137
10
date "+%Y_%m_%d_%H_%M_%S" 2021_02_15_12_00_29
11
date "+%Y_%m_%d_%H_%M_%S_%3N" 2021_02_15_12_00_29_137
12
date "+%Y.%m.%d %H:%M:%S" 2021.02.15 12:00:29
13
date "+%Y.%m.%d %H:%M:%S.%3N" 2021.02.15 12:00:29.137
14
date "+%Y-%m-%d %H:%M:%S" 2021-02-15 12:00:29
15
date "+%Y-%m-%d %H:%M:%S.%3N" 2021-02-15 12:00:29.137
16
date "+%Y.%m.%dT%H:%M:%S%z" 2021.02.15T12:00:29+0100