Convert string from __DATE__ into a time_t

c++, c-preprocessor, date, visual-c++

Solution

Edit: the corrected function should look something like this:

time_t cvt_TIME(char const *time) { 
    char s_month[5];
    int month, day, year;
    struct tm t = {0};
    static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";

    sscanf(time, "%s %d %d", s_month, &day, &year);

    month = (strstr(month_names, s_month)-month_names)/3;

    t.tm_mon = month;
    t.tm_mday = day;
    t.tm_year = year - 1900;
    t.tm_isdst = -1;

    return mktime(&t);
}

Problem

I'm trying to convert the string produced from the `__DATE__` macro into a `time_t`. I don't need a full-blown date/time parser, something that only handles the format of the `__DATE__` macro would be great. A preprocessor method would be nifty, but a function would work just as well. If it's relevant, I'm using MSVC.

Original source

Related problems