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 convertion fromString is invalid (guess because of time zone)
Forum Updated to NodeBB v4.3 + New Features

QDateTime convertion fromString is invalid (guess because of time zone)

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 217 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
    RoadCoder
    wrote on last edited by RoadCoder
    #1

    I have a date time format like this

    "2020-04-26T11:16:59+01:00"
    

    I tried this code and also different formatst, i always get an invalid QDateTime.

    QString datetime("2020-04-26T11:16:59+01:00");
    QString formatst("yyyy-MM-ddTHH:mm:ss±tzoff");
    //QString formatst("yyyy-MM-ddTHH:mm:ss±HH:mm");
    //QString formatst("yyyy-MM-ddTHH:mm:ssZHH:mm");   
    QDateTime dt;
    dt.fromString(datetime, formatst);
    qDebug() << Q_FUNC_INFO << datetime << dt;
    

    Can someone help to find convert the date/time from string?

    B 1 Reply Last reply
    0
    • R RoadCoder

      I have a date time format like this

      "2020-04-26T11:16:59+01:00"
      

      I tried this code and also different formatst, i always get an invalid QDateTime.

      QString datetime("2020-04-26T11:16:59+01:00");
      QString formatst("yyyy-MM-ddTHH:mm:ss±tzoff");
      //QString formatst("yyyy-MM-ddTHH:mm:ss±HH:mm");
      //QString formatst("yyyy-MM-ddTHH:mm:ssZHH:mm");   
      QDateTime dt;
      dt.fromString(datetime, formatst);
      qDebug() << Q_FUNC_INFO << datetime << dt;
      

      Can someone help to find convert the date/time from string?

      B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      @RoadCoder

      1. That's a Qt::ISODate format, you can use fromString(datetime, Qt::ISODate)
      2. QDateTime::fromString() is a static method, it won't do any change to your dt object.
        So the correct way is
      QDateTime dt = QDateTime::fromString(datetime, Qt::ISODate);
      
      1 Reply Last reply
      3

      • Login

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