How do I get GMT time in Unix? [closed]
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.
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()
).