我有一个在C++中使用strptime()函数的问题。使用strptime将字符串转换为时间,但得到垃圾
我在下面的stackoverflow中找到了一段代码,我想在struct tm上存储字符串时间信息。尽管我应该获得关于tm tm_year变量的年度信息,但我总是得到一些垃圾。是否有人可以帮助我?提前致谢。
string s = dtime;
struct tm timeDate;
memset(&timeDate,0,sizeof(struct tm));
strptime(s.c_str(),"%Y-%m-%d %H:%M", &timeDate);
cout<<timeDate.tm_year<<endl; // in the example below it gives me 113
cout<<timeDate.tm_min<<endl; // it returns garbage
**string s will be like "2013-12-04 15:03"**
@Kunal它始终是YYYY-MM-DD HH-MM喜欢2013年12月4日15:03 – caesar