Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QDateTime: How to hold dates before 1-1-1970?



  • Hello,
    The QDateTime is for dates after 1-1-1970 midnight. How can I hold dates before 1-1-1970? What if I want to represent a date from 1920? I don't need localization. I can't seem to find any suggestions/solutions for this...

    Thanks.


  • Lifetime Qt Champion

    Hi,

    What version of Qt are you using ?

     QDateTime dateTime(QDate(1900, 12, 12));
     qDebug() << dateTime;
    

    returns QDateTime(1900-12-12 00:00:00.000 CET Qt::LocalTime) as expected.



  • @SGaist
    It is only the ...SecsSinceEpoch() and the rules for DST which treat 1/1/1970 as "significant", is that right?



  • I misunderstood after reading lines like this in the documentation: "A datetime can also be set using the setMSecsSinceEpoch() function that takes the time, in milliseconds, since 00:00:00 on January 1, 1970". I should have just tried instantiating a date like @SGaist did. Like @JonB said, the 1970 seems to apply only those functions he stated. Thanks for clarifying.


Log in to reply