The easiest way to get the current GMT (Greenwich Mean Time) time in Unix is to use the date
command in the terminal with the -u
option, which tells the system to display the time in GMT (UTC) instead of the local time zone.
Command:
date -u
Explanation:
- The
-u
flag tells thedate
command to output the current time in UTC (Coordinated Universal Time), which is essentially the same as GMT. - This command will print the current date and time in GMT/UTC in a default format.
Example Output:
Thu Jan 17 12:34:56 UTC 2025
This gives you the current time in UTC, which is equivalent to GMT.
Additional Customization:
You can also format the output of the date
command to match specific requirements. For example, to get the GMT time in a specific format like YYYY-MM-DD HH:MM:SS
, you can use:
date -u +"%Y-%m-%d %H:%M:%S"
Example Output:
2025-01-17 12:34:56
This will provide the current GMT time in a more readable format.