• 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

    上面是demo测试,QTIMEZone和QDateTime在使用对象的时候,都要判断一下 isValid(),因为在Qt源码里面,这两个类的实现,都包含一个私有的d指针,来保证二进制兼容。在某些情况下,这个d指针可能为空,就会导致程序崩溃。

  • 相关阅读:
    win7下 iis配置 不能添加默认文档的 解决方案
    经典SQL语句大全
    Sql 行转列问题总结
    jQuery获取Select选择的Text和 Value(转)
    如何让虚拟目录里面的webconfig不继承网站的设置
    SQL2008 用户'sa'登录失败(错误18456)图文解决方法
    ASP.NET实现公历转农历的简单方法
    你的DNN站点慢了么?
    SQLServer2005删除log文件和清空日志的方案
    由于未能创建 Microsoft Visual C# 2008 编译器,因此未能打开项目 "xxx"
  • 原文地址:https://www.cnblogs.com/132818Creator/p/10101227.html
Copyright © 2020-2023  润新知