Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDateTime: How to hold dates before 1-1-1970?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 403 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JohnGa
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      3
      • SGaistS SGaist

        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.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

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

        1 Reply Last reply
        2
        • J Offline
          J Offline
          JohnGa
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved