Is there an inverse of gmtime()?

R

red floyd

Is there a portable way to convert between a struct tm and a time_t, for UTC?

I know that time_t is seconds since the epoch (1970-01-01T00:00:00Z).

Now, you can convert a time_t to a struct tm for either local (localtime()) or UTC (gmtime()).
But the reverse operation (mktime()) only converts a local time, as far as I can tell. What I'm
looking for is a portable way to convert a struct tm holding a UTC value into a time_t.

I'm currently using an OS specific kludge which involves setting the TZ environment variable, and
I know this is highly non-portable. Anybody got a better idea?

Thanks
 
G

Guest

Is there a portable way to convert between a struct tm and a time_t, for
UTC?

I know that time_t is seconds since the epoch (1970-01-01T00:00:00Z).

Now, you can convert a time_t to a struct tm for either local
(localtime()) or UTC (gmtime()).
But the reverse operation (mktime()) only converts a local time, as far
as I can tell. What I'm
looking for is a portable way to convert a struct tm holding a UTC value
into a time_t.

That means that time_t holds the value in the 0Z.
Now if you will do this you will have time_t in your zone ?
I'm currently using an OS specific kludge which involves setting the TZ
environment variable, and
I know this is highly non-portable. Anybody got a better idea?

Calculate the difference between gmtime(time_t) and localtime(time_t).
This is portable.



You are welcome.
 
R

red floyd

Is there a portable way to convert between a struct tm and a time_t,
for UTC?

[long winded question redacted]

Calculate the difference between gmtime(time_t) and localtime(time_t).
This is portable.

Duh! [slaps forehead] I should have thought of that one!

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top