1

无论时区如何,我都需要我的 Qt 应用程序在同一时刻在所有国际计算机上运行任务。应用程序以 UTC 从 Web 下载所需的日期 + 时间。我必须用什么时区初始化 QDateTime?世界标准时间?还是取决于当地时区?

例如:

假设所需的日期+时间是:2013 年 4 月 22 日 14:00 UTC

我将如何为一台配置了 EST 的计算机和另一台配置了 PST 的计算机初始化它?

会做:

QDateTime test(QDate(2013, 22, 4), QTime(14, 0, 0));

意味着所有国际计算机将同时运行该任务?

4

1 回答 1

3

The QDateTime constructor you are using takes a Qt::TimeSpec parameter, you can choose Qt::UTC instead of the default which is to use the local time. Then all the computers would run at the same time.

But if you're downloading the time from a service, it's presumably being transferred in ISO-8601 format. Then it's probably much easier to do it like this:

QDateTime test = QDateTime::fromString(dateAsAString, Qt::ISODate);

If the time service isn't returning the time in ISO-8601, then it is a bug in the service.

于 2013-04-22T01:41:10.440 回答