我有以下代码:
#include <stdio.h>
#include <time.h>
int main(void) {
time_t rawtime = time(NULL);
struct tm *ptm = localtime(&rawtime);
printf("The time is: %02d:%02d:%02d\n", ptm->tm_hour,
ptm->tm_min, ptm->tm_sec);
printf("The date is: %02d:%02d:%04d\n.", ptm->tm_mday, ptm->tm_mon, ptm->tm_year);
return 0;
}
当我运行它时,它返回
tm_year
的值为116而不是2016。有人可以告诉我为什么吗? 最佳答案
tm_year
字段表示为自1900年以来的年份:https://linux.die.net/man/3/localtime
关于c - 为什么年份在C中返回116而不是2016?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41320298/