time.strptime() method
time.strptime() method converts the string representing time to the struct_time object.
Example: Converting string to struct_time object.
This code uses the time
module to parse a formatted string representing a date and time and convert it into a time.struct_time
object. The time.strptime()
function is used for this purpose.
Python3
import time string = "Tue, 03 Aug 2021 10:45:08" obj = time.strptime(string, "%a, %d %b %Y %H:%M:%S" ) print (obj) |
Output
time.struct_time(tm_year=2021, tm_mon=8, tm_mday=3, tm_hour=10, tm_min=45, tm_sec=8, tm_wday=1, tm_yday=215, tm_isdst=-1)
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. So before starting with this module, we need to import it.