Tag: timezoneoffset

c中的strptime与时区偏移

我很难找到一种方法来解析时区,如下所示:“星期四,2011年9月1日09:06:03 -0400(美国东部时间)” 我需要在我的程序的更大方案中做的是接受char *并将其转换为time_t。 以下是我编写的一个简单的测试程序,试图找出strptime是否完全考虑时区,并且它似乎不是(当这个测试程序执行时,所有打印的数字在它们应该不同时是相同的)。 建议? 我也尝试使用GNU getdate和getdate_r,因为对于可能灵活的格式来说,这似乎是一个更好的选择,但我从编译器得到了一个“隐式函数声明”警告,暗示我没有包含正确的库。 还有其他我应该#include使用getdate吗? #include #include #include #include #ifndef __USE_XOPEN #define __USE_XOPEN #endif #include 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 = […]