Re: UTC string -> time_t



On 18 Dec, 13:41, Nick Keighley <nick_keighley_nos...@xxxxxxxxxxx>
wrote:
Hi,

this is probably quite easy...

How do I convert a UTC string into a time_t?

eg. "2007-12-18 13:37:26" -> a time_t.

Now FAQ 13.3 says use mktime() to convert a struct tm into
a time_t or you have to use some non-standard thing to parse the
string.
Assume I can parse the string and build a struct tm, how can I turn
it
into a time_t?

mktime() works on *local time* so it is going to apply the timezone
change
(the incoming string may have come from another timezone).

to save anyone the trouble of answering it looks like the way to
go is to calculate the difference between local time and UTC
by using difftime() on the results of localtime() and gmtime().
Adjusting the input value in struct tm then using mktime().

eek!


--
Nick Keighley



.



Relevant Pages

  • Re: how to store list of varying types
    ... When there's a variable-length string, ... typedef struct { ... pointer null, and the second one the CString object. ... then have to finish constructing the packet by copying the two data objects ...
    (microsoft.public.vc.mfc)
  • Re: UTC string -> time_t
    ... How do I convert a UTC string into a time_t? ... Now FAQ 13.3 says use mktime() to convert a struct tm into ... Assume I can parse the string and build a struct tm, ... objects to get the offset in minutes. ...
    (comp.lang.c)
  • Re: MVC in C++
    ... Things are now flowing more along the classic MVC lines. ... > struct Observable ... > string version; ... In that case the Controller would trigger a model update *and it* could ...
    (comp.object)
  • A note on personal corruption as a result of using C
    ... Many people in this ng are personally corrupt and use this ng to take ... "A string cannot contain Nuls" Yes it can. ... "A struct is a class" No, ... It appears that no C maven has read a history of mathematics. ...
    (comp.programming)
  • Re: Awfully quiet in here lately...
    ... before I did a test involving interning a string (resolving it via a hash so that strings with the same value will have the same pointer). ... the issue then is for floating point code, but I have found that even the current 28-bit flonums are "usually good enough" for the stuff I use the scripting for. ... hence, the current usual strategy of giving dynamic type-names to structs, but using static types for all of the struct fields. ...
    (comp.lang.misc)