次のような文字列からタイムゾーンを解析する方法を見つけるのに苦労しています: "Thu, 1 Sep 2011 09:06:03 -0400 (EDT)"
私のプログラムのより大きなスキームで行う必要があるのは、char* を取り込んで time_t に変換することです。以下は、strptime がタイムゾーンをまったく考慮しているかどうかを確認するために私が書いた簡単なテスト プログラムです。実際にはそうではないようです (このテスト プログラムを実行すると、出力されたすべての数値は異なるはずなのに同じになります)。提案?
GNU getdate と getdate_r も使用しようとしましたが、それはおそらく柔軟な形式のより良いオプションのように見えるためですが、コンパイラから「暗黙の関数宣言」警告が表示され、正しいライブラリが含まれていなかったことを意味します。getdate を使用するために #include する必要があるものは他にありますか?
#include <string.h>
#include <stdlib.h>
#include <strings.h>
#include <stdio.h>
#ifndef __USE_XOPEN
#define __USE_XOPEN
#endif
#include <time.h>
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;
}