I need to convert a string containing ASCII time and date (such as "Sun Sep 17 15:12:07 2006") to a time_t variable (or long). Converting time_t to ASCII is no problem (asctime). The other way around is a problem. Can anybody help me?
Basically the answer is: scan the string for separate components of date and time and fill the corresponding fields of a tm struct with the correct casting or adaptations (for example month is in the range 0÷11), next use mktime () function to obtain the corresponding time_t value. When using mktime () function, tm_yday and tm_wday are ignored.
Look at this example taken from Harbison & Steele manual: