這裏是man date
頁說,大約爲選項格式是什麼:
The --date=STRING is a mostly free format human readable date string such as
"Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next
Thursday". A date string may contain items indicating calendar date, time of day,
time zone, day of week, relative time, relative date, and numbers. An empty
string indicates the beginning of the day. The date string format is more
complex than is easily documented here but is fully described in the info
documentation.
因此,你可以使用,例如:
date --date "2014-06-12 09:03 UTC" --utc +%d.%m.%Y,\ %H:%M\ UTC
# Output: 12.06.2014, 09:03 UTC
得到你的願望。
你可以從你的第一輸出很容易得到這一第二種形式與sed
線如下:
sed 's/\([0-9]\{2\}\)\.\([0-9]\{2\}\)\.\([0-9]\{4\}\), \(.*\)/\3-\2-\1 \4/'
<<< '12.06.2014, 09:03 UTC'
# Output: 2014-06-12 09:03 UTC
注意,它可能會更快地輸出日期在ISO 8601的格式在第一時間進行再利用,例如與:
date --utc +%F\ %H:%M\ UTC
# Output: 2014-06-12 10:12 UTC
只需刪除逗號,並用斜線替換點:'日期-utc +%d /%m /%Y \%H:%M \ UTC'。 – fedorqui
您可以在'bsd date'中指定自定義日期格式,但不能在'gnu'中。 – BroSlow