Compatibility Members for QTime

以下成员源于类 QTime are part of the Qt compatibility layer. We advise against using them in new code.

静态公共成员

QTime currentTime (Qt::TimeSpec specification )

成员函数文档编制

[static] QTime QTime:: currentTime ( Qt::TimeSpec specification )

Returns the current time for the given specification .

To replace uses of this function where the specification is Qt::LocalTime , use the currentDate() overload that takes no parameters instead; otherwise, use QDateTime::currentDateTime () and convert the result to a UTC measurement.

例如,若有代码像

QTime localTime = QTime::currentTime(Qt::LocalTime);
QTime utcTime = QTime::currentTime(Qt::UTC);
					

可以把它重写成

QTime localTime = QTime::currentTime();
QTime utcTime = QTimeTime::currentDateTime().toUTC().time();
					

另请参阅 QDateTime::toUTC ().