Bash: get date and time from another time zone

2019-01-28 13:11发布


I would want to get the date and time from another time zone (UTC-4) with a bash command, but I don't want to configure it as the default TZ for the system.
Is there a simple way to do it?
E.g 1 (current):

$ date
fri nov  7 13:15:35 UTC 2014

E.g 2 (what I need):

$ date (+ some option for UTC-4)
fri nov  7 09:15:35 UTC 2014

3条回答
神经病院院长
2楼-- · 2019-01-28 13:13

You can use offset value in TZ to get the date for a different timezone:

TZ=UTC date -R
Fri, 07 Nov 2014 13:55:07 +0000

TZ=UTC+4 date -R
Fri, 07 Nov 2014 09:54:52 -0400
查看更多
祖国的老花朵
3楼-- · 2019-01-28 13:24

You could use

TZ=America/New_York date

or if you want to do date arithmetic you could use

date -d "+5 hours"
查看更多
贪生不怕死
4楼-- · 2019-01-28 13:34

If the other solutioons don't work, use

date --date='TZ="UTC+4" 2016-08-22 10:37:44' "+%Y-%m-%d %H:%M:%S"

2016-08-22 16:37:44

查看更多
登录 后发表回答