Reputation: 1266
I have a time object which looks like this:
time.struct_time(tm_year=2012, tm_mon=8, tm_mday=11, tm_hour=18, tm_min=48, tm_sec=23, tm_wday=5, tm_yday=224, tm_isdst=0)
I was wondering if there was an easy way add seconds to it.
I want to add 4497 seconds to it.
I've previously tried to convert each individual component to seconds and add them.
Thanks,
Parth
Upvotes: 2
Views: 3118
Reputation: 128991
Note: This answer applies to an old version of the question asking how to convert a time.struct_time
into an int
representing seconds and does not answer what the question currently asks (how to add a number of seconds to a time.struct_time
).
Assuming you want to convert to seconds since January 1, 1970, you can use:
time.mktime
for local time.calendar.timegm
for UTC time.These conversions (and their inverses) are detailed in the documentation for the time
module.
Upvotes: 2