QDate - wrong year

前端 未结 3 891
误落风尘
误落风尘 2021-01-22 01:39

I have the following situation:

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

the year returned is 1912.

3条回答
  •  北海茫月
    2021-01-22 01:56

    As described in the 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
    

    (Excuse the formatting, it's in a table in the docs). So you are going to have to pass the full year into the method until Qt decide 2012 is far enough into the century to change the default...

提交回复
热议问题