If my Unix machine is set to IST timezone, how can I get the current GMT time?
To find the unix current timestamp use the %s option in the date command. The %s option calculates unix timestamp by finding the number of seconds between the current date and unix epoch. You will get a different output if you run the above date command.
How to Adjust the Time on Linux. To set or change the time, use the timedatectl command together with the set-time subcommand. Note: You need to have elevated privileges to adjust the time or date. In the aforementioned command, the hh stands for hours, mm for minutes, and ss for seconds.
To display date and time under Linux operating system using command prompt use the date command. It can also display the current time / date in the given FORMAT. We can set the system date and time as root user too.
The date command under UNIX displays date and time. You can use the same command set date and time. You must be the super-user (root) to change the date and time on Unix like operating systems. The date command shows the date and time read from the kernel clock.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With