time.gmtime() Method in PythonIntroduction:In this tutorial, we are learning about the time.gmtime() method in Python. The Time module provides many time-related functions and is Python's standard utility module. The gmtime() method converts the time in seconds to struct_time in UTC format, where the dst flag is always zero. If sec is not provided or the value is None, then the current time returned by time() is used. The Time module's time.gmtime() method is used to convert time in seconds from time to time.struct_time object in UTC format; where the tm_isdst attribute is always 0. The time in seconds since local time edit a time.struct_time object returns, using the time.localtime() method. This method returns a time.struct_time object named tuple interface. The available values in the time.struct_time object are:
Syntax: The syntax of the time.gmtime() method in Python is given in below - Parameters: The parameter of the time.gmtime() method in Python is given below -
Return Value: The time.gmtime() method returns an object of the class "time.struct_time". Program Code 1: Here we give the program code of the time.gmtime() method in Python. The code is given below - Output: Now, we run the above code and find the output from it. The output is given below - time.struct_time(tm_year=2024, tm_mon=3, tm_mday=21, tm_hour=17, tm_min=56, tm_sec=11, tm_wday=3, tm_yday=81, tm_isdst=0) Program Code 2: Here we give another program code of the time.gmtime() method in Python. The code is given below - Output: Now, we run the above code and find the output from it. The output is given below - The gmtime is: time.struct_time(tm_year=2024, tm_mon=3, tm_mday=21, tm_hour=18, tm_min=0, tm_sec=1, tm_wday=3, tm_yday=81, tm_isdst=0) Program Code 3: Here we give another program code of the time.gmtime() method in Python. The code is given below - Output: Now, we run the above code and find the output from it. The output is given below - The time.struct_time object in seconds is: 600000 time.struct_time(tm_year=1970, tm_mon=1, tm_mday=7, tm_hour=22, tm_min=40, tm_sec=0, tm_wday=2, tm_yday=7, tm_isdst=0) The time.struct_time object in seconds is: 550000.8546 time.struct_time(tm_year=1970, tm_mon=1, tm_mday=7, tm_hour=8, tm_min=46, tm_sec=40, tm_wday=2, tm_yday=7, tm_isdst=0) Conclusion:In this tutorial, we are learning about the time.gmtime() method in Python. The gmtime() function, like the localtime() function, returns a time-struct time object. It accepts an argument in seconds since the epoch and returns the struct time in UTC format. Here, we also learn some program code for the time.gmtime() method in Python. Next TopicUnzip a list of tuples in python |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India