localtime返回null。为什么?(我正在使用Visual C++ 2008)
struct tm *tb;
time_t lDate;
time(&lDate);
tb = localtime(&lDate); // tb is null everytime I try this! 发布于 2011-03-28 21:10:55
这就是你的代码吗?我刚刚编译了这个程序,它工作得很好:
#include <stdio.h>
#include <time.h>
int main(int argc, char **argv)
{
struct tm *tb;
time_t lDate;
time(&lDate);
if (lDate == -1) {
perror("time");
return 1;
}
tb = localtime(&lDate);
if (tb == NULL) {
fprintf(stderr, "localtime failed\n");
return 1;
}
printf("Good\n");
return 0;
}发布于 2012-08-07 18:33:46
#include <time.h>
#include <stdio.h>
int main(void)
{
// get the current time
time_t now = time(0);
struct tm* theTime = localtime(&now);
int t=(int)theTime;
printf("%d",t);
getch();
return 0;
}它起作用了
发布于 2020-09-24 10:09:00
在项目中定义预处理器_USE_32BIT_TIME_T,然后重试。祝你好运:)
https://stackoverflow.com/questions/5459236
复制相似问题