tags:

views:

765

answers:

1

How do I do the above? There is mktime function but that treats the input as expressed in local time but how do i perform the conversion if my input tm variable happens to be in UTC.

+4  A: 

Use timegm() instead of mktime()

Martin York
Good answer - only demerit is that it is a non-standard (as in, not in POSIX or C standard) function.
Jonathan Leffler
I've seen other answers on the net that talk about getting the timezone offset using something like (note this is pseudo code - the parameters aren't right): difftime( mktime( gmtime( time())), mktime( localtime( time()))). But no one ever says how you apply this offset to your time_t variable.
Michael Burr
Does this work in windows too?