Write a Python program to get the GMT and local current time


The program is written in the Python programming language and uses the time module to work with dates and times. It calculates the current date and time in both GMT (Greenwich Mean Time) and the local time zone, and then prints the results. Here's a breakdown of the code:

  • The first line imports the "gmtime" function from the time module. The "gmtime" function returns the current time in GMT.
  • The second line imports the "strftime" function from the time module. The "strftime" function converts a time value to a string in a specified format.
  • The next line uses the "time.strftime()" function to convert the current GMT time to a string in a specified format, which is "%a, %d %b %Y %I:%M:%S %p %Z" . The "time.gmtime()" function is used to get the current GMT time. The resulting string is stored in a variable and displayed using the "print()" function with the message "GMT :".
  • The next line uses the "strftime()" function to convert the current local time to a string in the same format as before. The resulting string is displayed using the "print()" function with the message "Local:".

The program can be used to display the current date and time in a specified format, which can be useful in various applications, such as event scheduling, project management, and more. The output of the program shows the current date and time in both GMT and the local time zone, which can be useful for comparing time in different locations.

Source Code

from time import gmtime, strftime
import time
print("GMT : ",time.strftime("%a, %d %b %Y %I:%M:%S %p %Z", time.gmtime()))
print("Local: ",strftime("%a, %d %b %Y %I:%M:%S %p %Z"))

Output

GMT :  Sat, 24 Sep 2022 07:55:51 AM India Standard Time
Local:  Sat, 24 Sep 2022 01:25:51 PM India Standard Time

Example Programs