Python | time.gmtime() method Last Updated : 03 Jan, 2022 Comments Improve Suggest changes Like Article Like Report Time module in Python provides various time-related functions. This module comes under Python’s standard utility modules. time.gmtime() method of Time module is used to convert a time expressed in seconds since the epoch to a time.struct_time object in UTC in which tm_isdst attribute is always 0. To convert the given time in seconds since the epoch to a time.struct_time object in local time, time.localtime() method is used. This method returns a time.struct_time object with a named tuple interface. Following are the values present in time.struct_time object: Index Attribute Values 0 tm_year (for example, 1993) 1 tm_mon range [1, 12] 2 tm_mday range [1, 31] 3 tm_hour range [0, 23] 4 tm_min range [0, 59] 5 tm_sec range [0, 61] 6 tm_wday range [0, 6], Monday is 0 7 tm_yday range [1, 366] 8 tm_isdst 0, 1 or -1 N/A tm_zone abbreviation of timezone name N/A tm_gmtoff offset east of UTC in seconds Syntax: time.gmtime([secs]) Parameter: secs (optional): An integer or float value representing time in seconds. Fractions of specified seconds will be ignored. If the secs parameter is not provided or None then the current time as returned by time.time() method is used. Return type: This method returns an object of class 'time.struct_time'. Code #1: Use of time.gmtime() method Python3 # Python program to explain time.gmtime() method # importing time module import time # If secs parameter # is not given then # the current time # as returned by time.time() method # is used # Convert the current time in seconds # since the epoch to a # time.struct_time object in UTC obj = time.gmtime() # Print the time.struct.time object print(obj) Output: time.struct_time(tm_year=2019, tm_mon=8, tm_mday=22, tm_hour=3, tm_min=53, tm_sec=32, tm_wday=3, tm_yday=234, tm_isdst=0) Code #2: Use of time.gmtime() method Python3 # Python program to explain time.gmtime() method # importing time module import time # Time in seconds # since the epoch secs = 40000 # Convert the given time in seconds # since the epoch to a # time.struct_time object in UTC # using time.gmtime() method obj = time.gmtime(secs) # Print the time.struct_time object print("time.struct_time object for seconds =", secs) print(obj) # Time in seconds # since the epoch secs = 40000.7856 # Convert the given time in seconds # since the epoch to a # time.struct_time object in UTC # using time.gmtime() method obj = time.gmtime(secs) # Print the time.struct_time object print("\ntime.struct_time object for seconds =", secs) print(obj) # Output for sec = 40000 # and secs = 40000.7856 # will be same because # fractions in 40000.7856 # i.e .7856 will be ignored Output: time.struct_time object for seconds = 40000 time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=11, tm_min=6, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0) time.struct_time object for seconds = 40000.7856 time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=11, tm_min=6, tm_sec=40, tm_wday=3, tm_yday=1, tm_isdst=0) Reference: https://docs.python.org/3/library/time.html#time.gmtime Comment More infoAdvertise with us Next Article Python | time.gmtime() method I ihritik Follow Improve Article Tags : Python python-utility Practice Tags : python Similar Reads Python Time Module In this article, we will discuss the time module and various functions provided by this module with the help of good examples. As the name suggests Python time module allows to work with time in Python. It allows functionality like getting the current time, pausing the Program from executing, etc. S 7 min read Python | time.asctime() method Python time method time.asctime() is used to convert a tuple or a time.struct_time object representing a time as returned by time.gmtime() or time.localtime() method to a string of the following form: Day Mon Date Hour:Min:Sec Year For example: Thu 08 22 10:46:56 2019Python time asctime() Syntax: ti 3 min read Python time.pthread_getcpuclockid() Function The pthread_getcpuclockid() function returns the clock id of the thread-specific CPU-time clock for the specified thread_id. The thread ids are obtained from the different threads that are running being used by that program. The thread ids can be obtained using the 'ident' field of the threading cla 2 min read Python | time.clock_getres() method Time module in Python provides various time-related functions. This module comes under Pythonâs standard utility modules. time.clock_getres() method of Time module is used to get the resolution or precision of the specified clock clk_id. Basically, clk_id is a integer value which represents the id o 3 min read Python | time.clock_gettime() method time.clock_gettime() method of Time module is used to get the time of the specified clock clk_id. Basically, clk_id is a integer value which represents the id of the clock. Following are the constants available on UNIX platforms that can be used as value of clk_id parameter: clk_id clk_id constant M 3 min read Python | time.clock_gettime_ns() method Time module in Python provides various time-related functions. This module comes under Pythonâs standard utility modules. time.clock_gettime_ns() method of Time module is used to get the time (in nanoseconds) of the specified clock clk_id. Basically, clk_id is a integer value which represents the id 3 min read Python | time.clock_settime() method time.clock_settime() method of Time module is used to set the time (in seconds) of the specified clock clk_id. Basically, clk_id is a integer value which represents the id of the clock. Syntax: time.clock_settime(clk_id, seconds) Parameters: clk_id: A clk_id constant or an integer value representing 1 min read Python | time.clock_settime_ns() method time.clock_settime_ns() method of Time module is used to set the time (in nanoseconds) of the specified clock clk_id. Basically, clk_id is a integer value which represents the id of the clock. This method is similar to time.clock_settime() method which is used to set time of the specified clock clk_ 2 min read Python - time.ctime() Method Python time.ctime() method converts a time in seconds since the epoch to a string in local time. This is equivalent to asctime(localtime(seconds)). Current time is returned by localtime() is used when the time tuple is not present. Syntax: time.ctime([ sec ]) Parameter: sec: number of seconds to be 2 min read Python | time.get_clock_info() method Time module in Python provides various time related functions. time.get_clock_info() method in Time module is used to get the information on the specified clock name. This method return the information as a namespace object. The name of supported clocks and the method used to read that clock value a 2 min read Like