Skip to content

Instantly share code, notes, and snippets.

@krig
Created July 8, 2013 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krig/5952867 to your computer and use it in GitHub Desktop.
Save krig/5952867 to your computer and use it in GitHub Desktop.
(hopefully) fixed iso8601 parser. Should work in GNU/Linux systems now, at least.
/* parses only YYYY-MM-DDTHH:MM:SSZ */
time_t
parseiso8601utc_fixed(const char *date)
{
struct tm tt = {0};
double seconds;
if (sscanf(date, "%04d-%02d-%02dT%02d:%02d:%lfZ",
&tt.tm_year, &tt.tm_mon, &tt.tm_mday,
&tt.tm_hour, &tt.tm_min, &seconds) != 6)
return -1;
tt.tm_year -= 1900;
tt.tm_isdst = 0;
tt.tm_sec = (int)seconds;
tt.tm_mon--;
return timegm(&tt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment