time & date
timezone
timezone setup
tzdata installation with noninteractive
[!NOTE|label:references:]
or
[!NOTE|label:references:]
or in dockerfile
or ENV in dockerfile
[!NOTE|label:references:]
or
ARGin dockerfile[!NOTE|label:references:]
date
epoch
timestamps
format
[!TIP]
yyyy-MM-dd'T'HH:mm:ss.SSSZ
yyyy-MM-dd'T'HH:mm:ss
date +%c
locale’s date time
Sat May 9 11:49:47 2020
date +%x
locale’s date
05/09/20
date +%X
locale’s time
11:49:47
date +%A
locale’s full weekday name
Saturday
date +%B
locale’s full month name
May
date +%m-%d-%Y
MM-DD-YYYY date format
05-09-2020
date +%D
MM/DD/YY date format
05/09/20
date +%F
YYYY-MM-DD date format
2020-05-09
date +%T
HH:MM:SS time format
11:44:15
date +%u
Day of Week
6
date +%U
Week of Year with Sunday as first day of week
18
date +%V
ISO Week of Year with Monday as first day of week
19
date +%j
Day of Year
130
date +%Z
Timezone
PDT
date +%m
Month of year (MM)
05
date +%d
Day of Month (DD)
09
date +%Y
Year (YY)
2020
date +%H
Hour (HH)
11
date +%H
Hour (HH) in 24-hour clock format
11
date +%I
Hour in 12-hour clock format
11
date +%p
locale’s equivalent of AM or PM
AM
date +%P
same as %p but in lower case
am
classical date format
date format with timezone
details
IOS 8601
YYYY
2015
YYYY-MM
2015-12
YYYY-MM-DD
2015-12-11
YYYY-MM-DD'T'hh:mmTZD
2015-12-11T20:28+01:00 or 2015-12-11T19:28Z
YYYY-MM-DD'T'hh:mm:ssTZD
2015-12-11T20:28:30+01:00 or 2015-12-11T19:28:30Z
YYYY-MM-DD'T'hh:mm:ss.sTZD
2015-12-11T20:28:30.45+01:00 or 2015-12-11T19:28:30.45Z
where:
YYYY= four-digit year
MM= two-digit month (01=January, etc.)
DD= two-digit day of month (01 through 31)
hh= two digits of hour (00 through 23) (am/pm NOT allowed)
mm= two digits of minute (00 through 59)
ss= two digits of second (00 through 59)
s= one or more digits representing a decimal fraction of a second (i.e. milliseconds)
TZD= time zone designator (Z or +hh:mm or -hh:mm)
rfc-3339
utc
timezone
[!NOTE|label:references:]
list all timezone:
common formats
[!NOTE|label:references:] Shell command: date Most common Bash date commands for timestamping
YYYY-MM-DD
date -I
2020-10-09
YYYY-MM-DD_hh:mm:ss
date +%F_%T
2020-10-09_16:48:45
YYYYMMDD_hhmmss
date +%Y%m%d_%H%M%S
20201009_164845
YYYYMMDD_hhmmss (UTC version)
date --utc +%Y%m%d_%H%M%SZ
20201009_084845Z
YYYYMMDD_hhmmss (with local TZ)
date +%Y%m%d_%H%M%S%Z
20201009_164845CST
YYYYMMSShhmmss
date +%Y%m%d%H%M%S
20201009164845
YYYYMMSShhmmssnnnnnnnnn
date +%Y%m%d%H%M%S%N
20201009164845495302000
YYMMDD_hhmmss
date +%y%m%d_%H%M%S
201009_164845
Seconds since UNIX epoch:
date +%s
1602233325
Nanoseconds only:
date +%N
505337000
Nanoseconds since UNIX epoch:
date +%s%N
1602233325508581000
Nanoseconds since UNIX epoch:
date +%s%3N
1602233325508
ISO8601 UTC timestamp
date --utc +%FT%TZ
2020-10-09T08:48:45Z
ISO8601 UTC timestamp
date --utc +%FT%T%Z
2020-10-09T08:48:45UTC
ISO8601 UTC timestamp + ms
date --utc +%FT%T.%3NZ
2020-10-09T08:48:45.517Z
ISO8601 UTC timestamp + ms
date --utc +%FT%T.%3N%Z
2020-10-09T08:48:45.520UTC
ISO8601 Local TZ timestamp
date +%FT%T%Z
2020-10-09T16:48:45CST
YYYY-MM-DD (Short day)
date +%F\(%a\)
2020-10-09(Fri)
YYYY-MM-DD (Long day)
date +%F\(%A\)
2020-10-09(Friday)
convert
1 hour
3600 seconds
1 day
86400 seconds
1 week
604800 seconds
1 month (30.44 days)
2629743 seconds
1 year (365.24 days)
31556926 seconds
timestamps to epoch
epoch to timestamps
epoch with 13 digits
convert epoch with milliseconds
Convert unix timestamp to hh:mm:ss:SSS (where SSS is milliseconds)
result
convert in different timezone
[!NOTE|label:references:]
timezone can be found via:
get daylight saving
how many days from timestamps
[!NOTE|label:references:]
calculate time different
time described by STRING
two times different
with leading zero
with days
with nanoseconds
datediff (ddiff)
or with specific format
calculate with epoch
transfer date format
[!TIP]
chrony
install
from package management
from source
[!NOTE]
asciidoctor is required to build docs
conf
[!NOTE|label:references:]
210.72.145.44国家授时中心
ntp.aliyun.com阿里云
s1a.time.edu.cn北京邮电大学
s1b.time.edu.cn清华大学
s1c.time.edu.cn北京大学
s1d.time.edu.cn东南大学
s1e.time.edu.cn清华大学
s2a.time.edu.cn清华大学
s2b.time.edu.cn清华大学
s2c.time.edu.cn北京邮电大学
s2d.time.edu.cn西南地区网络中心
s2e.time.edu.cn西北地区网络中心
s2f.time.edu.cn东北地区网络中心
s2g.time.edu.cn华东南地区网络中心
s2h.time.edu.cn四川大学网络管理中心
s2j.time.edu.cn大连理工大学网络中心
s2k.time.edu.cnCERNET桂林主节点
s2m.time.edu.cn北京大学
ntp.sjtu.edu.cn|202.120.2.101上海交通大学
/etc/chrony.conf/usr/lib/systemd/system/chronyd.service
commands
services
server
chronyc
/usr/libexec/chrony-helper
/usr/libexec/chrony-helperset local time with chrony
[!NOTE|label:references:]
systemd-timesyncd
[!NOTE]
issue in
chronywith timedatactl
install
[!NOTE|label:references:]
enable and start services
config
[!NOTE]
commands
show-timesynctimesync-statuscheck log
Last updated
Was this helpful?