Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is there an inverse of gmtime()?

Reply
Thread Tools

Is there an inverse of gmtime()?

 
 
red floyd
Guest
Posts: n/a
 
      10-22-2003

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

 
Reply With Quote
 
 
 
 
grejdanospam@pacbell.net
Guest
Posts: n/a
 
      10-22-2003
On Wed, 22 Oct 2003 16:23:26 GMT, red floyd <(E-Mail Removed)> wrote:

>
> 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.


>
> Thanks
>
>



You are welcome.

--
grzegorz
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      10-23-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> On Wed, 22 Oct 2003 16:23:26 GMT, red floyd <(E-Mail Removed)> wrote:
>
>>
>> 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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query about tan inverse function jahaya@gmail.com VHDL 1 07-17-2005 01:27 PM
Java Reflection: Is there an inverse of Class.getComponentType() Benjamin Johnston Java 1 01-06-2005 06:36 AM
is there a inverse polynomial for the CRC generator polynomial Chen L. C Programming 2 07-06-2004 01:23 AM
Inverse of 'chop @array' gusmeister Perl 1 03-06-2004 01:28 AM
CEF vs MLPPP vs Inverse Multiplex SysAdmin Cisco 1 11-20-2003 01:51 PM



Advertisments