55

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

codeforester
  • 39,467
  • 16
  • 112
  • 140
Sam
  • 747
  • 1
  • 8
  • 14

4 Answers4

81

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.

codaddict
  • 445,704
  • 82
  • 492
  • 529
40

Like this with date shell command :

date -u
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
6

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

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
6

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

julumme
  • 2,326
  • 2
  • 25
  • 38