如何在Unix中获得GMT时间?

时间:2021-12-22 15:59:59

If my Unix machine is set to IST timezone, how can I get the current GMT time?

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

4 个解决方案

#1


38  

You can use the -u option of date command:

您可以使用date命令的-u选项:

date -u

-u Display (or set) the date in Greenwich Mean Time (GMT-universal time), bypassing the normal conversion to (or from) local time.

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

#2


22  

Try doing this with date shell command :

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

date -u

#3


3  

If you're doing this from a shell script, you can use date -u, which gives you UTC.

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

From C, you would use time() in conjunction with gmtime() to give yourself a struct tm with the required data (gmtime() gives UTC, unlike localtime()).

从C开始,您可以将time()与gmtime()结合使用,为自己提供一个包含所需数据的struct tm(gmtime()给出UTC,与localtime()不同)。

#4


2  

In command line, you can set a timezone to the one you would like to see, and check the time with date command, before returning to the original one.

在命令行中,您可以将时区设置为您想要查看的时区,并在返回原始时间之前使用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

Also of course, as suggested, to see just universal time, you can use the one suggested before

当然,正如建议的那样,只要看一下普遍时间,就可以使用之前建议的那个

#1


38  

You can use the -u option of date command:

您可以使用date命令的-u选项:

date -u

-u Display (or set) the date in Greenwich Mean Time (GMT-universal time), bypassing the normal conversion to (or from) local time.

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

#2


22  

Try doing this with date shell command :

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

date -u

#3


3  

If you're doing this from a shell script, you can use date -u, which gives you UTC.

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

From C, you would use time() in conjunction with gmtime() to give yourself a struct tm with the required data (gmtime() gives UTC, unlike localtime()).

从C开始,您可以将time()与gmtime()结合使用,为自己提供一个包含所需数据的struct tm(gmtime()给出UTC,与localtime()不同)。

#4


2  

In command line, you can set a timezone to the one you would like to see, and check the time with date command, before returning to the original one.

在命令行中,您可以将时区设置为您想要查看的时区,并在返回原始时间之前使用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

Also of course, as suggested, to see just universal time, you can use the one suggested before

当然,正如建议的那样,只要看一下普遍时间,就可以使用之前建议的那个