Python | time.localtime() method Last Updated : 14 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Time module in Python provides handy tools to work with time-related tasks. One of its most useful functions is time.localtime(), which converts time expressed in seconds since the epoch (January 1, 1970) into a local time representation. It returns a time.struct_time object, which is a tuple-like structure containing detailed components like year, month, day, hour, etc. If no time is passed, time.localtime() returns the current local time.Here's what the returned object contains:IndexAttributeDescription0tm_yearYear (e.g., 2025)1tm_monMonth (1–12)2tm_mdayDay of the month (1–31)3tm_hourHour (0–23)4tm_minMinute (0–59)5tm_secSecond (0–61, includes leap sec)6tm_wdayWeekday (0–6, Monday is 0)7tm_ydayDay of the year (1–366)8tm_isdstDaylight Saving (0, 1, or -1)Syntaxtime.localtime([secs]) Parameter: secs (optional): Number of seconds since the epoch. If omitted or None, the current time is used.Return type: object of class 'time.struct_time'. Examples of time.localtime() MehodExample 1: Get current local time Python import time obj = time.localtime() print(obj) print(time.asctime(obj)) Outputtime.struct_time(tm_year=2025, tm_mon=4, tm_mday=12, tm_hour=11, tm_min=38, tm_sec=10, tm_wday=5, tm_yday=102, tm_isdst=0) Sat Apr 12 11:38:10 2025 Explanation:time.localtime() gives you the current time broken down into its parts.time.asctime() converts the struct_time into a readable string like "Thu Apr 10 16:35:12 2025".Example 2: Convert specific time (in seconds) to local time Python import time secs = 950000000 obj = time.localtime(secs) print("Local time for seconds =", secs) print(obj) OutputLocal time for seconds = 950000000 time.struct_time(tm_year=2000, tm_mon=2, tm_mday=8, tm_hour=8, tm_min=53, tm_sec=20, tm_wday=1, tm_yday=39, tm_isdst=0) Explanation:Here, 950000000 represents a specific point in time.time.localtime(secs) converts it to a full struct_time format based on your local timezone.Example 3: What happens with fractional seconds? Python import time # Time with fractional seconds secs = 950000000.81956 obj = time.localtime(secs) print("Local time for seconds =", secs) print(obj) OutputLocal time for seconds = 950000000.81956 time.struct_time(tm_year=2000, tm_mon=2, tm_mday=8, tm_hour=8, tm_min=53, tm_sec=20, tm_wday=1, tm_yday=39, tm_isdst=0) Explanation:Although we passed a float (950000000.81956), the fractional part is ignored.We'll get the same result as if you passed 950000000 as an integer.Reference:https://docs.python.org/3/library/time.html#time.localtime Comment More infoAdvertise with us Next Article Python | time.localtime() 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