如何在Unix中获得GMT时间?

Sam*_*Sam 41 unix linux date unix-timestamp

如果我的Unix机器设置为IST时区,我如何获得当前的GMT时间?

cod*_*ict 63

您可以使用-udate命令选项:

date -u
Run Code Online (Sandbox Code Playgroud)

-u以格林威治标准时间(GMT-通用时间)显示(或设置)日期,绕过正常转换为(或从当地时间).


Gil*_*not 28

尝试使用dateshell命令执行此操作:

date -u
Run Code Online (Sandbox Code Playgroud)


pax*_*blo 5

如果您是通过Shell脚本执行此操作,则可以使用date -u,它为您提供UTC。

在C中,您可以time()结合使用和gmtime()来给自己struct tm提供所需的数据(gmtime()不同于,提供UTC localtime())。


jul*_*mme 5

在命令行中,可以将时区设置为要查看的时区,并使用date命令检查时间,然后再返回到原始时区。

#see current timezone
(date +%Z)

#change to a desired ie. London
export TZ=England/London

#or LA would be
export TZ=America/Los_Angeles

#check the time
date
Run Code Online (Sandbox Code Playgroud)

当然,也如建议的那样,要看到世界时间,您可以使用之前建议的时间