qt获取当前时区utc_QT的时区转换以及使用注意事项

该博客介绍了如何在QT中进行时区转换,从本地时间到UTC,包括QDateTime的使用方法,如fromString、toTimeZone、currentDateTime等,以及如何获取当前时区ID和UTC时间。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值