Tag: strptime

strptime给出“隐含声明”和“未定义引用”

所以,当我使用strptime函数strptime我得到一个警告: warning: implicit declaration of function ‘strptime’ 然后是错误: undefined reference to ‘strptime’ 是的,我已经包含了time.h 这是我使用它的一个小示例代码。 #include void my_function() { char buf* = “2016-02-05 12:45:10”; struct tm time*; … strptime(buf, “%F %T”, &time); … } 我知道time.h正在工作,因为在同一个.c文件中,我正在使用strftime , time_t和来自time.h ‘struct tm而没有问题。 我知道这很strptime ,因为当我评论这行代码时,它编译没有任何问题。

c / c ++ strptime()不解析%Z时区名称

我是C的新手。当我练习C来隐蔽时间来刺激来回构造时。 我发现有些不同。 请告诉我做错了什么。 #include #include #include /* test different format string to strptime ” %A, %b %d, %X %z %Y ” ” %A, %b %d, %X %Z %Y ” */ int main(int argc,char *argv[]) { char date[] = “6 Mar 2001 12:33:45”; char fmt[80]; struct tm tm; if (argc==1) return 0; strcpy(fmt,argv[1]); memset(&tm, 0, sizeof(struct […]

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 = […]