QDate - 错误的年份

  • 本文关键字:错误 QDate qt qdate
  • 更新时间 :
  • 英文 :


我有以下情况:

   QDate fixDate = QDate::fromString(QString("270912"), "ddMMyy");

返回的年份是1912。我不明白为什么以及如何获得正确的年份。

提前致谢

两位数的年份总是解释为19xx。因此,您可以通过YYYY或只是将100添加到年份中。

如文档中所述:

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年足以进入本世纪以更改默认值...

你能用ddMMyyyy代替ddMMyy吗?或者您需要这种格式的日期?

在此处查找有关 fromString 方法的更多信息

最新更新