QT的时区转换以及使用注意事项

QDateTime localDate = QDateTime::fromString("2018-12-11 10:40:00", "yyyy-MM-dd hh:mm:ss");//输入的时间
QDateTime utcDate = localDate.toTimeZone(zone);//拿到的是0时区的当前时间
QDateTime currentTime = QDateTime::currentDateTime();//当前时区的当前时间
QDateTime changeLocaldate = QDateTime::fromMSecsSinceEpoch(localDate.toMSecsSinceEpoch(), Qt::UTC);
QDateTime changeutcDate = changeLocaldate.toTimeZone(zone);
QTimeZone currentZone = currentTime.timeZone();
QString currentZoneId = currentZone.id();//当前时间的当前时区
QDateTime currentUtcTime = QDateTime::currentDateTimeUtc();//当前的UTC时间

ERROR_TRACE("Local Date: %s", localDate.toString().toUtf8().data());
ERROR_TRACE("utc Date: %s", utcDate.toString().toUtf8().data());
ERROR_TRACE("Current Date: %s", currentTime.toString().toUtf8().data());
ERROR_TRACE("change Current Date: %s", changeLocaldate.toString().toUtf8().data());
ERROR_TRACE("change Current utc Date: %s", changeutcDate.toString().toUtf8().data());
ERROR_TRACE("Current Zone Id: %s", currentZoneId.toUtf8().data());
ERROR_TRACE("Current UTC Date: %s", currentUtcTime.toString().toUtf8().data());

[E:uiMeetData+10304:2104] 2018-12-11 11:31:33.676 96466.536706 Test trace test
[E:uiMeetData+10304:2104] 2018-12-11 11:31:33.676 96466.536949 Utc zone id UTC
[E:uiMeetData+10304:2104] 2018-12-11 11:31:33.677 96466.537928 Local Date: 周二 12月 11 10:40:00 2018
[E:uiMeetData+10304:2104] 2018-12-11 11:31:33.677 96466.538217 utc Date: 周二 12月 11 02:40:00 2018 GMT
[E:uiMeetData+10304:2104] 2018-12-11 11:31:33.678 96466.538517 Current Date: 周二 12月 11 11:31:33 2018
[E:uiMeetData+10304:2104] 2018-12-11 11:31:33.678 96466.538853 change Current Date: 周二 12月 11 02:40:00 2018 GMT
[E:uiMeetData+10304:2104] 2018-12-11 11:31:33.678 96466.539169 change Current utc Date: 周二 12月 11 02:40:00 2018 GMT
[E:uiMeetData+10304:2104] 2018-12-11 11:31:33.678 96466.539389 Current Zone Id: Asia/Shanghai
[E:uiMeetData+10304:2104] 2018-12-11 11:31:33.679 96466.539554 Current UTC Date: 周二 12月 11 03:31:33 2018 GMT

猜你喜欢

转载自www.cnblogs.com/132818Creator/p/10101227.html