The time.strptime()f
unction converts a string representing time/date to a struct_time
object. struct_time
is a data structure defined in the time
module, used to represent date and time information.
strptime(string, format = None)
copy
string |
A required string representation of the timestamp to be converted to struct_time |
format |
An optional string detailing the format of the string. |
The function returns the struct_time
object representing the input time.
If the format is not given, the function will assume the default format, '%a %b %d %H:%M:%S %Y' e.g Wed Feb 19 16:48:17 2020 .
The time.ctime() function converts seconds representing a timestamp since the epoch to a string formatted similarly to the default format.
with a custom format
We can use the format parameter to indicate to the strptime()
function how the input time is presented The format parameter is a string that contains formatting codes that indicate for example, if the date is presented as "YYYY-MM-DD HH:MM:SS" then the format string should be "%Y-%m-%d %H:%M:%S".