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. How convert time in string to QDateTime
Forum Updated to NodeBB v4.3 + New Features

How convert time in string to QDateTime

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 3.5k 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.
  • R Offline
    R Offline
    RyuShai
    wrote on last edited by
    #1

    here the string i got from server :

    2019-03-12T03:24:30.282Z
    

    how to convert this to Qdatetime, i try

    QDateTime time = QDateTime::fromString("2019-03-12T03:24:30.282Z","yyyy-MM-ddTHH_mm_ss.zzzZ");
    

    but result invalid

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Hm, your code should work, it's correct.

      Try this:

      QDateTime time = QDateTime::fromString("2019-03-12T03:24:30.282Z", Qt::ISODateWithMs);
      

      (Z(:^

      sierdzioS 1 Reply Last reply
      1
      • sierdzioS sierdzio

        Hm, your code should work, it's correct.

        Try this:

        QDateTime time = QDateTime::fromString("2019-03-12T03:24:30.282Z", Qt::ISODateWithMs);
        
        sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        @sierdzio said in How convert time in string to QDateTime:

        Hm, your code should work, it's correct.

        Huh, nope I read it wrongly. You've mixed the characters a bit.

        QDateTime time = QDateTime::fromString("2019-03-12T03:24:30.282Z","yyyy-MM-ddTHH:mm:ss.zzzZ");
        

        (Z(:^

        R 1 Reply Last reply
        3
        • sierdzioS sierdzio

          @sierdzio said in How convert time in string to QDateTime:

          Hm, your code should work, it's correct.

          Huh, nope I read it wrongly. You've mixed the characters a bit.

          QDateTime time = QDateTime::fromString("2019-03-12T03:24:30.282Z","yyyy-MM-ddTHH:mm:ss.zzzZ");
          
          R Offline
          R Offline
          RyuShai
          wrote on last edited by
          #4

          @sierdzio
          Qt::ISODateWithMs is worked
          ty, you save my day

          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