Obsolete Members for QDateTime

以下成员源于类 QDateTime 被弃用。 提供它们是为使旧源代码能继续工作。强烈建议不要在新代码中使用它们。

公共函数

(deprecated in 6.9) QDateTime (QDate date , QTime time , Qt::TimeSpec spec , int offsetSeconds = 0)
(deprecated in 6.9) void setOffsetFromUtc (int offsetSeconds )
(deprecated in 6.9) void setTimeSpec (Qt::TimeSpec spec )
(deprecated in 6.9) QDateTime toTimeSpec (Qt::TimeSpec spec ) const

静态公共成员

(deprecated in 6.9) QDateTime fromMSecsSinceEpoch (qint64 msecs , Qt::TimeSpec spec , int offsetSeconds = 0)
(deprecated in 6.9) QDateTime fromSecsSinceEpoch (qint64 secs , Qt::TimeSpec spec , int offsetSeconds = 0)

成员函数文档编制

[deprecated in 6.9] QDateTime:: QDateTime ( QDate date , QTime time , Qt::TimeSpec spec , int offsetSeconds = 0)

This function is deprecated since 6.9. We strongly advise against using it in new code.

使用 QDateTime(date, time) or QDateTime(date, time, QTimeZone::fromSecondsAheadOfUtc(offsetSeconds)) .

构造日期时间采用给定 date and time , using the time representation implied by spec and offsetSeconds 秒。

date 有效和 time is not, the time will be set to midnight.

spec 不是 Qt::OffsetFromUTC then offsetSeconds will be ignored. If spec is Qt::OffsetFromUTC and offsetSeconds 为 0 那么 timeSpec () 会被设为 Qt::UTC , i.e. an offset of 0 seconds.

spec is Qt::TimeZone then the spec will be set to Qt::LocalTime , i.e. the current system time zone. To create a Qt::TimeZone datetime use the correct constructor.

date lies outside the range of dates representable by QDateTime, the result is invalid. If spec is Qt::LocalTime and the system's time-zone skipped over the given date and time, the result is invalid.

[static, deprecated in 6.9] QDateTime QDateTime:: fromMSecsSinceEpoch ( qint64 msecs , Qt::TimeSpec spec , int offsetSeconds = 0)

This function is deprecated since 6.9. We strongly advise against using it in new code.

这是重载函数。

传递 QTimeZone instead, or omit spec and offsetSeconds .

Returns a datetime representing a moment the given number msecs of milliseconds after the start, in UTC, of the year 1970, described as specified by spec and offsetSeconds .

Note that there are possible values for msecs that lie outside the valid range of QDateTime , both negative and positive. The behavior of this function is undefined for those values.

spec 不是 Qt::OffsetFromUTC 那么 offsetSeconds 会被忽略。若 spec is Qt::OffsetFromUTC offsetSeconds is 0 then Qt::UTC will be used as the spec , since UTC has zero offset.

spec is Qt::TimeZone then Qt::LocalTime will be used in its place, equivalent to using the current system time zone (but differently represented).

另请参阅 fromSecsSinceEpoch (), toMSecsSinceEpoch (),和 setMSecsSinceEpoch ().

[static, deprecated in 6.9] QDateTime QDateTime:: fromSecsSinceEpoch ( qint64 secs , Qt::TimeSpec spec , int offsetSeconds = 0)

This function is deprecated since 6.9. We strongly advise against using it in new code.

这是重载函数。

传递 QTimeZone instead, or omit spec and offsetSeconds .

Returns a datetime representing a moment the given number secs of seconds after the start, in UTC, of the year 1970, described as specified by spec and offsetSeconds .

Note that there are possible values for secs that lie outside the valid range of QDateTime , both negative and positive. The behavior of this function is undefined for those values.

spec 不是 Qt::OffsetFromUTC 那么 offsetSeconds 会被忽略。若 spec is Qt::OffsetFromUTC offsetSeconds is 0 then Qt::UTC will be used as the spec , since UTC has zero offset.

spec is Qt::TimeZone then Qt::LocalTime will be used in its place, equivalent to using the current system time zone (but differently represented).

另请参阅 fromMSecsSinceEpoch (), toSecsSinceEpoch (),和 setSecsSinceEpoch ().

[deprecated in 6.9] void QDateTime:: setOffsetFromUtc ( int offsetSeconds )

This function is deprecated since 6.9. We strongly advise against using it in new code.

使用 setTimeZone ( QTimeZone::fromSecondsAheadOfUtc (offsetSeconds)) instead

设置 timeSpec () 到 Qt::OffsetFromUTC and the offset to offsetSeconds . The datetime may refer to a different point in time.

The maximum and minimum offset is 14 positive or negative hours. If offsetSeconds is larger or smaller than that, then the result is undefined.

offsetSeconds 为 0 那么 timeSpec () 会被设为 Qt::UTC .

另请参阅 setTimeZone (), isValid (), offsetFromUtc (),和 toOffsetFromUtc ().

[deprecated in 6.9] void QDateTime:: setTimeSpec ( Qt::TimeSpec spec )

This function is deprecated since 6.9. We strongly advise against using it in new code.

使用 setTimeZone () 代替

Sets the time specification used in this datetime to spec . The datetime may refer to a different point in time.

spec is Qt::OffsetFromUTC 那么 timeSpec () 会被设为 Qt::UTC , i.e. an effective offset of 0.

spec is Qt::TimeZone then the spec will be set to Qt::LocalTime , i.e. the current system time zone.

范例:

QDateTime local(QDateTime::currentDateTime());
qDebug() << "Local time is:" << local;
QDateTime UTC(local);
UTC.setTimeSpec(Qt::UTC);
qDebug() << "UTC time is:" << UTC;
qDebug() << "There are" << local.secsTo(UTC) << "seconds difference between the datetimes.";
					

另请参阅 setTimeZone (), timeSpec (), toTimeSpec (), setDate (),和 setTime ().

[deprecated in 6.9] QDateTime QDateTime:: toTimeSpec ( Qt::TimeSpec spec ) const

This function is deprecated since 6.9. We strongly advise against using it in new code.

使用 toTimeZone () 代替。

Returns a copy of this datetime converted to the given time spec .

The result represents the same moment in time as, and is equal to, this datetime.

spec is Qt::OffsetFromUTC 那么它被设为 Qt::UTC . To set to a fixed offset from UTC, use toTimeZone () 或 toOffsetFromUtc ().

spec is Qt::TimeZone 那么它被设为 Qt::LocalTime , i.e. the local Time Zone. To set a specified time-zone, use toTimeZone ().

范例:

QDateTime local(QDateTime::currentDateTime());
QDateTime UTC(local.toTimeSpec(Qt::UTC));
qDebug() << "Local time is:" << local;
qDebug() << "UTC time is:" << UTC;
qDebug() << "No difference between times:" << local.secsTo(UTC);
					

另请参阅 setTimeSpec (), timeSpec (),和 toTimeZone ().