Well I think the title sums it up. Suppose I have an object of type double
which I obtained from running std::difftime
on two time_t
objects, and now I want to add the resulting number of seconds back to a time_t
object. I don't mind losing fractions of seconds.
Note that the number of seconds might be large (ie. larger than the 60 seconds allowed in struct tm
, but always lower than any integer primitive used to represent seconds on the respective machine / implementation, and never larger than the order of 1 year, although preferably I would not like this to be a restriction).
How would I go about doing this portably (ie. as per C standard)?
I am hoping not to have to divide into months, days, hours, minutes etc. and add them manually to struct tm
object. Surely there's a better way!?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…