【发布时间】:2010-04-05 14:29:01
【问题描述】:
我有以下代码:
const char* timeformat = "%Y-%m-%d %H:%M:%S";
const int timelength = 20;
char timecstring[timelength];
strftime(timecstring, timelength, timeformat, currentstruct);
cout << "timecstring is: " << timecstring << "\n";
currentstruct 是一个 tm*。 cout 以正确的格式给我日期,但年份不是 2010 年,而是 3910 年。我知道从 1900 年开始的年份与年份有关,但我不确定如何让 strftime 识别这一点而不是将 1900 添加到 2010 的值上,任何人都可以帮忙。
问候
保罗
【问题讨论】:
-
这完全取决于您如何填充 currentstruct。可以发一下吗?
-
C 规范说 tm_years 是“自 1900 年以来的年数”。为什么不坚持标准并避免这整个混乱?