How do I get GMT time in Unix?

LinuxDateUnixUnix Timestamp

Linux Problem Overview


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

Linux Solutions


Solution 1 - Linux

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.

Solution 2 - Linux

Like this with date shell command :

date -u

Solution 3 - Linux

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()).

Solution 4 - Linux

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSamView Question on Stackoverflow
Solution 1 - LinuxcodaddictView Answer on Stackoverflow
Solution 2 - LinuxGilles QuenotView Answer on Stackoverflow
Solution 3 - LinuxpaxdiabloView Answer on Stackoverflow
Solution 4 - LinuxjulummeView Answer on Stackoverflow