I'm having trouble finding a way to parse the time zone from strings, for example: "Thu, Sep 1, 2011 09:06:03 AM -0400 (EDT)"
What I need to do in a larger scheme of my program, take char * and convert it to time_t. The following is a simple test program that I wrote to try to find out that strptime takes into account the time zone in general, and it doesn't seem to be so (when this test program runs all the printed numbers are the same, when they should be different). Suggestions?
I also tried using GNU getdate and getdate_r because it seems like the best option for possible flexible formats, but I got an implicit function warning from the compiler, implying that I did not include the correct libraries. Is there anything else I need to include #include to use getdate?
int main (int argc, char** argv){
char *timestr1, *timestr2, *timestr3;
struct tm time1, time2, time3;
time_t timestamp1, timestamp2, timestamp3;
timestr1 = "Thu, 1 Sep 2011 09:06:03 -0400 (EDT)"; // -4, and with timezone name
timestr2 = "Thu, 1 Sep 2011 09:06:03 -0000"; // -0
strptime(timestr1, "%a, %d %b %Y %H:%M:%S %Z", &time1); //includes UTC offset
strptime(timestr2, "%a, %d %b %Y %H:%M:%S %Z", &time2); //different UTC offset
strptime(timestr1, "%a, %d %b %Y %H:%M:%S", &time3); //ignores UTC offset
time1.tm_isdst = -1;
timestamp1 = mktime(&time1);
time2.tm_isdst = -1;
timestamp2 = mktime(&time2);
time3.tm_isdst = -1;
timestamp3 = mktime(&time3);
printf("Hello \n");
printf("%d\n%d\n%d\n", timestamp1, timestamp2, timestamp3);
printf("Check the numbers \n");
return 0;
}