4

I'm looking for the datetime from qt to return me the string as an isodate but with the timezone. I looked on the web for sometimes for my problem but found no solution

I just got this:

this->ui.dateEnd->dateTime().toString(Qt::ISODate);

giving me this:

1900-10-31T23:00:00Z

Or also this:

this->ui.dateEnd->dateTime().toUfc().toString(Qt::ISODate);

giving me this:

1900-10-31T23:00:00Z

and i want this:

1900-10-31T23:00:00+01.00.00

Thank you if someone have an idea!

1
  • dateTime.toTimeSpec(Qt::OffsetFromUTC).toString(Qt::ISODate) should work (according to docs), but it seems that there is a bug.
    – user362638
    Commented Sep 11, 2013 at 20:53

1 Answer 1

5

Got around the bug that I mentioned in the comments:

QDateTime local = QDateTime::currentDateTime();
QDateTime utc = local.toUTC();
utc.setTimeSpec(Qt::LocalTime);

qint64 const utcOffset = utc.secsTo(local);

qDebug() << local.toString(Qt::ISODate);
qDebug() << utc.toString(Qt::ISODate);
qDebug() << utcOffset;

local.setUtcOffset(utcOffset);
qDebug() << local.toString(Qt::ISODate);

This outputs:

"2013-09-12T00:17:39"  
"2013-09-11T21:17:39"  
10800 
"2013-09-12T00:17:39+03:00"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.