我有这个代码:
#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/