Results 1 to 2 of 2

Thread: Converting QString to QDateTime with format

  1. #1
    Join Date
    Aug 2018
    Qt products

    Question Converting QString to QDateTime with format


    i am trying to convert a simple QString to a QDateTime using some format. The conversion doesn't work -> The QDateTime object "dt" is not valid. What is wrong?
    I am using Qt 5.

    QString strValue = "2018-08-09T12:38:57.709000Z";
    QString format = "yyyy-MM-ddTHH:mm:ss.zzzzzzZ";
    QDateTime dt = QDateTime::fromString (strValue, format);

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 590 Times in 580 Posts
    Qt products
    Unix/X11 Windows Android

    Default Re: Converting QString to QDateTime with format

    Looks like too many digits in the milliseconds field. QDateTime::fromString() seems to imply only "z" or "zzz" (3 digits max) are allowed in this field, because the range is given as 000 - 999. What would "709000" in the ms field mean, anyway? 709 seconds? Or 709.000 ms? The parser doesn't know.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Converting __DATE__ to ISO format
    By BobTheProg in forum Qt Programming
    Replies: 9
    Last Post: 9th December 2015, 14:30
  2. QDateTime application level format string
    By davidovv in forum Qt Programming
    Replies: 12
    Last Post: 10th March 2013, 16:53
  3. Replies: 5
    Last Post: 1st June 2011, 09:28
  4. Replies: 5
    Last Post: 10th May 2011, 21:38
  5. converting image into monochrome format
    By aj2903 in forum Qt Programming
    Replies: 2
    Last Post: 13th November 2009, 16:53


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.