Question

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

Was it helpful?

Solution

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:

These conversions (and their inverses) are detailed in the documentation for the time module.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top