scieck
6th February 2012, 04:04
Hello,
shouldn't line 2 and line 4 below print the same UTC time?
Line 2 prints the correct UTC time, but line 4 prints local time.
The variable utc is holding UTC time, then calling utc.toTime_t() should return number of seconds from epoch to UTC, is this right ?
Then on line 4, a new QDateTime is built using the number of seconds from epoch to UTC, so shouldn't this print UTC time again?
QDateTime utc = QDateTime::currentDateTimeUtc();
qDebug() << utc;
uint time = utc.toTime_t();
qDebug() << QDateTime::fromTime_t(time); // this prints local time which is UTC + 9 hours
output:
QDateTime("Mon Feb 6 04:00:48 2012")
QDateTime("Mon Feb 6 13:00:48 2012")
shouldn't line 2 and line 4 below print the same UTC time?
Line 2 prints the correct UTC time, but line 4 prints local time.
The variable utc is holding UTC time, then calling utc.toTime_t() should return number of seconds from epoch to UTC, is this right ?
Then on line 4, a new QDateTime is built using the number of seconds from epoch to UTC, so shouldn't this print UTC time again?
QDateTime utc = QDateTime::currentDateTimeUtc();
qDebug() << utc;
uint time = utc.toTime_t();
qDebug() << QDateTime::fromTime_t(time); // this prints local time which is UTC + 9 hours
output:
QDateTime("Mon Feb 6 04:00:48 2012")
QDateTime("Mon Feb 6 13:00:48 2012")