Re: Timezone conversion

Discussion in 'C Programming' started by Nobody, Mar 29, 2012.

  1. Nobody

    Nobody Guest

    On Wed, 28 Mar 2012 17:42:06 +0200, Guillaume Dargaud wrote:

    > Given a date/time string and a time zone, such as
    > 2012/03/28 14:26:19 UTC
    >
    > I would like to convert it to another time zone, in this case:
    > 2012/03/28 16:26:19 CEST
    >
    > How can I do that in standard C, taking into account daylight savings ?


    In C99, you can use mkxtime(). However, it's currently not implemented by
    either GNU libc or MSVCRT.

    mktime() -> offset -> localtime() sort of works, but you have to know the
    correct offset, which is easier said than done in the vicinity of daylight
    time changes (e.g. if one timezone has just switched to DST while the
    other is about to switch).

    POSIX specifies tzset(), which allows you to switch timezones. So you can
    use mktime() followed by localtime() with a different timezone in each
    case.

    > Is it enough to play with gmtime/localtime knowing that the PC that does the
    > conversion is in CEST ? I assume the system knows when daylight savings
    > start/end and that C uses it, right ?


    Maybe. IIUC, a system might only support UTC (i.e. gmtime() and
    localtime() are identical), or it might only support UTC and an
    unspecified "local" timezone.

    Modern systems are likely to have some form of timezone database, but the
    mechanism for accessing it is platform-specific.
    Nobody, Mar 29, 2012
    #1
    1. Advertising

  2. Nobody

    Kaz Kylheku Guest

    On 2012-03-29, Nobody <> wrote:
    > In C99, you can use mkxtime(). However, it's currently not implemented by
    > either GNU libc or MSVCRT.


    Gee, let's standardize something that still won't be present on GNU/Linux or
    Windows 13 years from now ...
    Kaz Kylheku, Mar 29, 2012
    #2
    1. Advertising

  3. Nobody

    Ben Pfaff Guest

    Nobody <> writes:

    > In C99, you can use mkxtime(). However, it's currently not implemented by
    > either GNU libc or MSVCRT.


    I can't find mkxtime() in C99.
    --
    "In My Egotistical Opinion, most people's C programs should be indented six
    feet downward and covered with dirt." -- Blair P. Houghton
    Ben Pfaff, Mar 29, 2012
    #3
  4. Nobody

    Nobody Guest

    On Thu, 29 Mar 2012 12:34:35 -0700, William Ahern wrote:

    >> > In C99, you can use mkxtime(). However, it's currently not implemented by
    >> > either GNU libc or MSVCRT.

    >
    >> I can't find mkxtime() in C99.

    >
    > As far as I can tell, it was proposed for and rejected by C99.


    Oops; I was looking at an earlier draft. It isn't present in N1256.
    Nobody, Apr 1, 2012
    #4
    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. Bijoy Naick

    Timezone conversion

    Bijoy Naick, Dec 17, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    6,328
    =?Utf-8?B?QnJldHQgRWRtYW4=?=
    Apr 18, 2005
  2. RAMK
    Replies:
    4
    Views:
    55,868
    juan.farre
    Jan 31, 2012
  3. asaf
    Replies:
    3
    Views:
    6,143
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Sep 11, 2006
  4. axrock
    Replies:
    8
    Views:
    949
    Roedy Green
    Mar 25, 2009
  5. Ami
    Replies:
    5
    Views:
    277
Loading...

Share This Page