Inspired from @Peter Kofler answer for 2022-12-13T17:15:53.499Z
kind of dates:
int64_t dateTime_parse(char *dateString)
{
char *format = "%d-%d-%dT%d:%d:%d.%dZ";
struct tm t{};
int msec;
int parseCount = sscanf(dateString, format, &t.tm_year, &t.tm_mon,
&t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec, &msec);
if (parseCount < 7)
{
return - 1;
}
t.tm_year -= 1900;
t.tm_mon -= 1;
t.tm_isdst = -1; //let mktime figure out DST
int64_t result = mktime(&t); //this is time_t type
result *= 1000;
result += msec;
return result;
}
Note that mktime
assumes first parameter to be a pointer to local time. If you want the date string to be parsed as UTC, use _mkgmtime instead (in windows).