09-18-2006 05:04 AM
09-18-2006 07:46 AM
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:
#include <time.h>
double Secs_Since_April_15 () {
struct tm Apr_15_struct = { 0 };
time_t Apr_15_t;
Apr_15_struct.tm_year = 90;
Apr_15_struct.tm_mon = 3;
Apr_15_struct.tm_mday = 15;
Apr_15_t = mktime (&Apr_15_struct);
if (Apr_15_t == (yime_t)-1) // Error
return 0.0;
else
return difftime (time (NULL), Apr_15_t);
}