我必须找到距离现在 4,000,000 秒的日期。如果我将 4,000,000 添加到 ,我可以得到正确的答案secondsSince1970
,但我想知道为什么如果我添加 4,000,000 它不起作用now.tm_sec
?
int main(int argc, const char * argv[])
{
long secondsSince1970 = time(NULL) + 4000000;
struct tm now;
localtime_r(&secondsSince1970, &now);
printf("The date from 4,000,000 seconds from now is %i-%i-%i\n", now.tm_mon + 1, now.tm_wday, now.tm_year + 1900);
}
输出:日期是 10-1-2012
int main(int argc, const char * argv[])
{
long secondsSince1970 = time(NULL);
struct tm now;
localtime_r(&secondsSince1970, &now);
now.tm_sec += 4000000;
printf("The date from 4,000,000 seconds from now is %i-%i-%i\n", now.tm_mon + 1, now.tm_wday, now.tm_year + 1900);
}
输出:日期是 8-4-2012