我有以下代码:
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";
Run Code Online (Sandbox Code Playgroud)
电流结构是一个tm*.cout给了我正确格式的日期,但是这一年不是2010年,而是3910.我知道这与1900年开始的年份有关,但我不知道如何让strftime认识到这一点而不是添加1900到那里的2010年的价值,任何人都可以帮助.
问候
保罗
根据定义,tm_yeara 的字段struct tm是自1900年以来的年数.处理a的每一段代码都struct tm希望如此.您无法设置tm_year为2010并期望代码能够神奇地确定您真正意味着2010年而不是3910年.
设置tm_year为110,strftime并将工作.
| 归档时间: |
|
| 查看次数: |
701 次 |
| 最近记录: |