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. QDateTimeFromString question
Qt 6.11 is out! See what's new in the release blog

QDateTimeFromString question

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 256 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    If I call:

    m_DateTime = QDateTime::fromString(strDateTime, "yyyy-MM-ddThh:mm:ss");
    

    with input of "2023-12-06T02:00:56", it works, but if I call it with input of "2023-12-06T02:00:56.481" it returns an invalid QDateTime.

    Should I expect that? I would have expected it to be tolerant of trailing sub-seconds?

    Paul ColbyP 1 Reply Last reply
    0
    • PerdrixP Perdrix

      If I call:

      m_DateTime = QDateTime::fromString(strDateTime, "yyyy-MM-ddThh:mm:ss");
      

      with input of "2023-12-06T02:00:56", it works, but if I call it with input of "2023-12-06T02:00:56.481" it returns an invalid QDateTime.

      Should I expect that? I would have expected it to be tolerant of trailing sub-seconds?

      Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      @Perdrix said in QDateTimeFromString question:

      Should I expect that? I would have expected it to be tolerant of trailing sub-seconds?

      Yes, you should expect that. If there's trailing milliseconds, you should add .zzz (or .z) to the format string. See https://doc.qt.io/qt-6/qtime.html#fromString-4

      Cheers.

      PerdrixP 1 Reply Last reply
      4
      • Paul ColbyP Paul Colby

        @Perdrix said in QDateTimeFromString question:

        Should I expect that? I would have expected it to be tolerant of trailing sub-seconds?

        Yes, you should expect that. If there's trailing milliseconds, you should add .zzz (or .z) to the format string. See https://doc.qt.io/qt-6/qtime.html#fromString-4

        Cheers.

        PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #3

        @Paul-Colby Thank you

        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