How do I get GMT time in Unix? [closed]

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


You can use the -u option of date command:

date -u

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


Like this with date shell command :

date -u

If you're doing this from a shell script, you can use date -u, which gives you 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()).


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.

#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