Results 1 to 7 of 7

Thread: inside localtime() - wondering how to easily extract timezone difference

  1. #1
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default inside localtime() - wondering how to easily extract timezone difference

    I quote from man localtime:
    The ctime(), gmtime() and localtime() functions all take an argument of data type time_t which represents calendar time. When interpreted as an absolute time value, it represents the number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
    Now I get this time_t value using time(NULL), and pass a pointer to that value to localtime() to get the local time as a struct tm. I wonder how localtime finds out the time zone value which is not a part of the time_t value (as far as I can make out from the man page.

    Any hints as to this would be appreciated. Otherwise I have to do some circus with finding out the difference between the values returned by localtime and gmtime.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  2. #2
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: inside localtime() - wondering how to easily extract timezone difference

    Quoting from man 3p localtime
    The localtime() function shall convert the time in seconds since the Epoch pointed to by timer into a broken-down time, expressed as a local time. The function corrects for the timezone and any seasonal time adjustments. Local timezone information is used as though localtime() calls tzset().
    So man tzset has the answers (if I understood your question right)
    Last edited by yop; 9th January 2006 at 14:03.

  3. #3
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: inside localtime() - wondering how to easily extract timezone difference

    Quote Originally Posted by yop
    Quoting from man 3p localtime
    So man tzset has the answers (if I understood your question right)
    Well ya I forgot to mention that I have read through tzset - but it appears to be a UNIX-specific thing. How would then the localtime() function compile/work on DOS/Windows?
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: inside localtime() - wondering how to easily extract timezone difference

    Quote Originally Posted by jamadagni
    Well ya I forgot to mention that I have read through tzset - but it appears to be a UNIX-specific thing. How would then the localtime() function compile/work on DOS/Windows?
    Does it matter? The most important part is that it works (if it works, because localtime() is not an ANSI C function, so I guess non-posix Windows may not have it), right? Let's leave libc programming to libc programmers.

  5. #5
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: inside localtime() - wondering how to easily extract timezone difference

    http://cygwin.com/cygwin-api/cygwin-api.html (but be warned the water is getting deeper )

  6. #6
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: inside localtime() - wondering how to easily extract timezone difference

    Quote Originally Posted by wysota
    localtime() is not an ANSI C function
    Of course it's an ANSI C function - it is listed and described by K&R in their ANSI C book.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: inside localtime() - wondering how to easily extract timezone difference

    "man localtime" gives this as compliance standards:

    SVID 3, POSIX, BSD 4.3, ISO 9899

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.