Command - date
Example 1 date - convert unix epoch timestamp to date string
$ date --date='@1617694020'
Tue 06 Apr 2021 07:27:00 AM UTC
Example 2 date - convert unix timestamp to custom formatted date string
$ date +"%Y-%m-%d %H:%m" --date='@1617694020'
2021-04-06 07:04
$ date --date='@1617694020.904'
Tue 06 Apr 2021 07:27:00 AM UTC
Example 3 date -- MacOS Mojave convert timestamp to date string
## MacOS Mojave not support --date
$ date --date='@1617694020.904'
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
## use -r to instead
$ date -r 1625043610 +"%Y%m%d %H:%M:%S"
20210630 17:00:10
沒有留言:
張貼留言