Is there an inverse of gmtime()?

Discussion in 'C++' started by red floyd, Oct 22, 2003.

  1. red floyd

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

    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
     
    red floyd, Oct 22, 2003
    #1
    1. Advertising

  2. red floyd

    Guest

    On Wed, 22 Oct 2003 16:23:26 GMT, red floyd <> 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
     
    , Oct 22, 2003
    #2
    1. Advertising

  3. red floyd

    red floyd Guest

    wrote:

    > On Wed, 22 Oct 2003 16:23:26 GMT, red floyd <> 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!
     
    red floyd, Oct 23, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephen
    Replies:
    1
    Views:
    1,228
    Purl Gurl
    May 19, 2004
  2. Benjamin Johnston
    Replies:
    1
    Views:
    489
    Mike Schilling
    Jan 6, 2005
  3. John Hunter

    datetimes, tzinfo and gmtime epoch

    John Hunter, Apr 16, 2004, in forum: Python
    Replies:
    0
    Views:
    311
    John Hunter
    Apr 16, 2004
  4. Florian Lindner

    timedelta comparision with gmtime()

    Florian Lindner, Jun 22, 2005, in forum: Python
    Replies:
    1
    Views:
    501
  5. Chen L.
    Replies:
    2
    Views:
    892
    Dik T. Winter
    Jul 6, 2004
Loading...

Share This Page