我有以下情况:
QDate fixDate = QDate::fromString(QString("270912"), "ddMMyy");返回的年份是1912。我不明白为什么以及如何得到正确的年份。
提前感谢
发布于 2012-09-27 22:14:26
两位数的年份总是被解释为19xx。因此,您可以传递YYYY或仅将100添加到years。
发布于 2012-09-27 21:42:53
如docs中所述
For any field that is not represented in the format the following defaults are used:
Year 1900
Month 1
Day 1
// For example:
QDate::fromString("1.30", "M.d"); // January 30 1900
QDate::fromString("20000110", "yyyyMMdd"); // January 10, 2000(请原谅格式,它在文档中的一个表中)。因此,您将不得不将全年传递到方法中,直到Qt决定2012年已经足够进入本世纪,可以更改默认设置……
发布于 2012-09-27 21:44:04
你能用ddMMyy代替ddMMyyyy吗?或者您需要此格式的日期?
Look here for more information about fromString method
https://stackoverflow.com/questions/12622654
复制相似问题