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::fromString wrong result...
Qt 6.11 is out! See what's new in the release blog

QDateTime::fromString wrong result...

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 486 Views 1 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I want to convert the date time string to a date, I am doing this:

    QDateTime dtToSet(QDateTime::fromString("2022-04-26 15:02:00", "yyyy-MM-dd HH:mm:ss"));
    

    I've done quite a few searches online and from what I can see the syntax and formatting options are correct, but from the above the date in the debugger dtToSet shows as:

    Fri Jun 5 00:00:00 143463
    

    Why ?

    Kind Regards,
    Sy

    Christian EhrlicherC 1 Reply Last reply
    0
    • SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #3

      Ok, so I added the following:

      const QDate cdtTemp(dtToSet.date());
      const QDate ctmTemp(dtToSet.time());
      

      cdtTemp contains Tue Apr 26 2022
      ctmTemp contains 15:02:00

      So there is nothing wrong with the code its just an order display of dtToSet being incorrect in the Qt Creator debugger.

      Kind Regards,
      Sy

      1 Reply Last reply
      0
      • SPlattenS SPlatten

        I want to convert the date time string to a date, I am doing this:

        QDateTime dtToSet(QDateTime::fromString("2022-04-26 15:02:00", "yyyy-MM-dd HH:mm:ss"));
        

        I've done quite a few searches online and from what I can see the syntax and formatting options are correct, but from the above the date in the debugger dtToSet shows as:

        Fri Jun 5 00:00:00 143463
        

        Why ?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @SPlatten said in QDateTime::fromString wrong result...:

        Why ?

        Because your output is not what you save into dtToSet. Please show the full code.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #3

          Ok, so I added the following:

          const QDate cdtTemp(dtToSet.date());
          const QDate ctmTemp(dtToSet.time());
          

          cdtTemp contains Tue Apr 26 2022
          ctmTemp contains 15:02:00

          So there is nothing wrong with the code its just an order display of dtToSet being incorrect in the Qt Creator debugger.

          Kind Regards,
          Sy

          1 Reply Last reply
          0

          • Login

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