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. [solved] QDateTime::fromString missing seconds.
Forum Updated to NodeBB v4.3 + New Features

[solved] QDateTime::fromString missing seconds.

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.3k 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.
  • J Offline
    J Offline
    Jeroen3
    wrote on last edited by Jeroen3
    #1

    When running the following code in Qt 5.4.1 mingw Win7x64.

    QString bLine("2015-06-03T12.20.55Z");
    QDateTime begintime = QDateTime::fromString(bLine, Qt::ISODate);
    qDebug() << bLine << " --> " << begintime.toString(Qt::ISODate);
    

    I get weird results.

    "2015-06-03T12.20.55Z"  -->  "2015-06-03T12:20:33Z"
    

    Where did the 22 seconds go? Leap seconds?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on last edited by
      #2

      It's probably because you used a period (.) as the time separator instead of a colon and it interpreted what you meant to be 55 seconds as 55/100 of a minute (33 seconds).

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jeroen3
        wrote on last edited by
        #3

        No way.

        "2015-06-03T12.20.99Z"  -->  "2015-06-03T12:20:59Z"
        

        So this is an bug right? Since ISO 8601 uses 0-59+1 (for leap seconds) and not 0-99.
        The Qdocu says "the second with a leading zero (00 to 59)" for ss.
        Workaround:

        QString bLine("2015-06-03T12.20.30Z");
        QString format("yyyy-MM-ddThh.mm.ssZ");
        QDateTime begintime = QDateTime::fromString(bLine, format);
        qDebug() << bLine << " --> " << begintime.toString(Qt::ISODate);
        

        However, that will fail on leap seconds. Which I don't need... yet...

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mchinand
          wrote on last edited by
          #4

          Why don't you just use:

          QString bLine("2015-06-03T12:20:55Z");
          QDateTime begintime = QDateTime::fromString(bLine, Qt::ISODate);
          

          Qt::ISODate expects colons between hours, minutes, and seconds, (HH:mm:ss) so your result isn't surprising.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jeroen3
            wrote on last edited by
            #5

            Because it reads 20.30 minutes instead of 20 minutes and 30 seconds.
            I'll find and replace the dots with semicolons. Semicolons are not supported in file names, that why dots are used.
            It's so obvious if you think about it....

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mchinand
              wrote on last edited by mchinand
              #6

              OK, it's not so obvious when you hadn't mentioned that the date-time string was being used for a filename. Also, this is a colon (:) and this is a semicolon (;).

              1 Reply Last reply
              0
              • Pablo J. RoginaP Offline
                Pablo J. RoginaP Offline
                Pablo J. Rogina
                wrote on last edited by
                #7

                @Jeroen3 please use the proper time format separator which is a colon (:)

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                J 1 Reply Last reply
                0
                • Pablo J. RoginaP Pablo J. Rogina

                  @Jeroen3 please use the proper time format separator which is a colon (:)

                  J Offline
                  J Offline
                  Jeroen3
                  wrote on last edited by
                  #8

                  @Pablo-J.-Rogina Yes I will QString::replace . for : (a colon).
                  Since the filename timestamp and file content timestamp are created using the same routine on an proprietary platform I cannot use a colon initially.

                  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