Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 793
Sam Avatar asked Nov 19 '12 07:11

Sam


People also ask

How do you display time in Unix?

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 do I fix the time in Linux?

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.

What is the command to display current time Linux?

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.

How do you change the time on a UNIX server?

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.


4 Answers

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 image 63
codaddict Avatar answered Sep 30 '22 04:09

codaddict


Like this with date shell command :

date -u
like image 34
Gilles Quenot Avatar answered Sep 30 '22 03:09

Gilles Quenot


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

like image 30
paxdiablo Avatar answered Sep 30 '22 05:09

paxdiablo


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

like image 42
julumme Avatar answered Sep 30 '22 05:09

julumme