Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: time functions weirdness Date: Sat, 17 Sep 2016 17:04:02 -0700 Organization: None to speak of Lines: 24 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="15983"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18cReID+LII0lZv8YMwOM2O" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:Dz+D2tQtQvQAU32kP6Navx7LJ2Q= sha1:6JRdZNRZ0/m+1iwqwyjzsVdV30U= Xref: csiph.com comp.lang.c:93700 Robert Latest writes: > the task is simple: Convert a time string to a time_t and back. I'm not even > concerned with timezones, I want everything to be in UTC. But for some > reason it just doesn't work and I don't know why. Is it possible that > mktime()'s and gmtime()'s notions of the UNIX epoch differ by one hour? [...] localtime() converts a time_t value to a struct tm value representing a local time. gmtime() converts a time_t value to a struct tm value representing a UTC time. mktime() is essentially the inverse of localtime(); it converts a struct tm value representing a local time to a time_t value. There is no inverse of the gmtime() function. This is IMHO quite unfortunate, and I don't know why something like a mktime_utc() function (perhaps with a better name) was never added to the standard. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"