QTimeZone 类

QTimeZone identifies how a time representation relates to UTC. 更多...

头: #include <QTimeZone>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

此类 equality-comparable .

注意: 此类的所有函数 thread-safe .

公共类型

struct OffsetData
(从 6.5 起) enum 初始化 { LocalTime, UTC }
enum NameType { DefaultName, LongName, ShortName, OffsetName }
OffsetDataList
enum TimeType { StandardTime, DaylightTime, GenericTime }

公共函数

QTimeZone ()
(从 6.5 起) QTimeZone (QTimeZone::Initialization spec )
QTimeZone (int offsetSeconds )
QTimeZone (const QByteArray & ianaId )
QTimeZone (const QByteArray & zoneId , int offsetSeconds , const QString & name , const QString & abbreviation , QLocale::Territory territory = QLocale::AnyTerritory, const QString & comment = QString())
QTimeZone (const QTimeZone & other )
QTimeZone (QTimeZone && other )
~QTimeZone ()
QString abbreviation (const QDateTime & atDateTime ) const
(从 6.5 起) QTimeZone asBackendZone () const
QString comment () const
int daylightTimeOffset (const QDateTime & atDateTime ) const
QString displayName (const QDateTime & atDateTime , QTimeZone::NameType nameType = QTimeZone::DefaultName, const QLocale & locale = QLocale()) const
QString displayName (QTimeZone::TimeType timeType , QTimeZone::NameType nameType = QTimeZone::DefaultName, const QLocale & locale = QLocale()) const
(从 6.5 起) int fixedSecondsAheadOfUtc () const
bool hasDaylightTime () const
bool hasTransitions () const
QByteArray id () const
bool isDaylightTime (const QDateTime & atDateTime ) const
(从 6.5 起) bool isUtcOrFixedOffset () const
bool isValid () const
QTimeZone::OffsetData nextTransition (const QDateTime & afterDateTime ) const
QTimeZone::OffsetData offsetData (const QDateTime & forDateTime ) const
int offsetFromUtc (const QDateTime & atDateTime ) const
QTimeZone::OffsetData previousTransition (const QDateTime & beforeDateTime ) const
int standardTimeOffset (const QDateTime & atDateTime ) const
void swap (QTimeZone & other )
(从 6.2 起) QLocale::Territory territory () const
(从 6.5 起) Qt::TimeSpec timeSpec () const
CFTimeZoneRef toCFTimeZone () const
NSTimeZone * toNSTimeZone () const
QTimeZone::OffsetDataList transitions (const QDateTime & fromDateTime , const QDateTime & toDateTime ) const
QTimeZone & operator= (const QTimeZone & other )
QTimeZone & operator= (QTimeZone && other )

静态公共成员

const int MaxUtcOffsetSecs
const int MinUtcOffsetSecs
QList<QByteArray> availableTimeZoneIds ()
QList<QByteArray> availableTimeZoneIds (QLocale::Territory territory )
QList<QByteArray> availableTimeZoneIds (int offsetSeconds )
QTimeZone fromCFTimeZone (CFTimeZoneRef timeZone )
(从 6.5 起) QTimeZone fromDurationAheadOfUtc (std::chrono::seconds offset )
QTimeZone fromNSTimeZone (const NSTimeZone * timeZone )
(从 6.5 起) QTimeZone fromSecondsAheadOfUtc (int offset )
(从 6.4 起) QTimeZone fromStdTimeZonePtr (const int * timeZone )
QByteArray ianaIdToWindowsId (const QByteArray & ianaId )
bool isTimeZoneIdAvailable (const QByteArray & ianaId )
(从 6.5 起) bool isUtcOrFixedOffset (Qt::TimeSpec spec )
QTimeZone systemTimeZone ()
QByteArray systemTimeZoneId ()
QTimeZone utc ()
QByteArray windowsIdToDefaultIanaId (const QByteArray & windowsId )
QByteArray windowsIdToDefaultIanaId (const QByteArray & windowsId , QLocale::Territory territory )
QList<QByteArray> windowsIdToIanaIds (const QByteArray & windowsId )
QList<QByteArray> windowsIdToIanaIds (const QByteArray & windowsId , QLocale::Territory territory )
bool operator!= (const QTimeZone & lhs , const QTimeZone & rhs )
bool operator== (const QTimeZone & lhs , const QTimeZone & rhs )

详细描述

When dates and times are combined, the meaning of the result depends on how time is being represented. There are various international standards for representing time; one of these, UTC, corresponds to the traditional standard of solar mean time at Greenwich (a.k.a. GMT). All other time systems supported by Qt are ultimately specified in relation to UTC. An instance of this class provides a stateless calculator for conversions between UTC and other time representations.

Some time representations are simply defined at a fixed offset to UTC. Others are defined by governments for use within their jurisdictions. The latter are properly known as time zones, but QTimeZone (since Qt 6.5) is unifies their representation with that of general time systems. One time zone generally supported on most operating systems is designated local time; this is presumed to correspond to the time zone within which the user is living.

For time zones other than local time, UTC and those at fixed offsets from UTC, Qt can only provide support when the operating system provides some way to access that information. When Qt is built, the timezone feature controls whether such information is available. When it is not, some constructors and methods of QTimeZone are excluded from its API; these are documented as depending on feature timezone . Note that, even when Qt is built with this feature enabled, it may be unavailable to users whose systems are misconfigured, or where some standard packages (for example, the tzdata package on Linux) are not installed. This feature is enabled by default when time zone information is available.

This class is primarily designed for use in QDateTime ; most applications will not need to access this class directly and should instead use an instance of it when constructing a QDateTime .

注意: For consistency with QDateTime , QTimeZone does not account for leap seconds.

备注

QTimeZone, like QDateTime , measures offsets from UTC in seconds. This contrasts with their measurement of time generally, which they do in milliseconds. Real-world time zones generally have UTC offsets that are whole-number multiples of five minutes (300 seconds), at least since well before 1970. A positive offset from UTC gives a time representation puts noon on any given day before UTC noon on that day; a negative offset puts noon after UTC noon on the same day.

Lightweight Time Representations

QTimeZone can represent UTC, local time and fixed offsets from UTC even when feature timezone is disabled. The form in which it does so is also available when the feature is enabled; it is a more lightweight form and processing using it will typically be more efficient, unless methods only available when feature timezone is enabled are being exercised. See 初始化 and QTimeZone::fromSecondsAheadOfUtc (int) for how to construct these representations.

This documentation distinguishes between "time zone", used to describe a time representation described by system-supplied or standard information, and time representations more generally, which include these lightweight forms. The methods available only when feature timezone is enabled are apt to be cheaper for time zones than for lightweight time representations, for which these methods may construct a suitable transient time zone object to which to forward the query.

IANA Time Zone IDs

QTimeZone uses the IANA time zone IDs as defined in the IANA Time Zone Database (http://www.iana.org/time-zones). This is to ensure a standard ID across all supported platforms. Most platforms support the IANA IDs and the IANA Database natively, but for Windows a mapping is required to the native IDs. See below for more details.

The IANA IDs can and do change on a regular basis, and can vary depending on how recently the host system data was updated. As such you cannot rely on any given ID existing on any host system. You must use availableTimeZoneIds () to determine what IANA IDs are available.

The IANA IDs and database are also know as the Olson IDs and database, named after the original compiler of the database.

UTC Offset Time Zones

A default UTC time zone backend is provided which is always available when feature timezone is enabled. This provides a set of generic Offset From UTC time zones in the range UTC-16:00 to UTC+16:00. These time zones can be created using either the standard ISO format names, such as "UTC+00:00", as listed by availableTimeZoneIds (), or using a name of similar form in combination with the number of offset seconds.

Windows Time Zones

Windows native time zone support is severely limited compared to the standard IANA TZ Database. Windows time zones cover larger geographic areas and are thus less accurate in their conversions. They also do not support as much historical data and so may only be accurate for the current year. In particular, when MS's zone data claims that DST was observed prior to 1900 (this is historically known to be untrue), the claim is ignored and the standard time (allegedly) in force in 1900 is taken to have always been in effect.

QTimeZone uses a conversion table derived from the Unicode CLDR data to map between IANA IDs and Windows IDs. Depending on your version of Windows and Qt, this table may not be able to provide a valid conversion, in which "UTC" will be returned.

QTimeZone provides a public API to use this conversion table. The Windows ID used is the Windows Registry Key for the time zone which is also the MS Exchange EWS ID as well, but is different to the Time Zone Name (TZID) and COD code used by MS Exchange in versions before 2007.

注意: When Qt is built with the ICU library, it is used in preference to the Windows system APIs, bypassing all problems with those APIs using different names.

System Time Zone

The method systemTimeZoneId () returns the current system IANA time zone ID which on Unix-like systems will always be correct. On Windows this ID is translated from the Windows system ID using an internal translation table and the user's selected country. As a consequence there is a small chance any Windows install may have IDs not known by Qt, in which case "UTC" will be returned.

Creating a new QTimeZone instance using the system time zone ID will only produce a fixed named copy of the time zone, it will not change if the system time zone changes. QTimeZone::systemTimeZone () will return an instance representing the zone named by this system ID. Note that constructing a QDateTime using this system zone may behave differently than constructing a QDateTime that uses Qt::LocalTime as its Qt::TimeSpec , as the latter directly uses system APIs for accessing local time information, which may behave differently (and, in particular, might adapt if the user adjusts the system zone setting).

Time Zone Offsets

The difference between UTC and the local time in a time zone is expressed as an offset in seconds from UTC, i.e. the number of seconds to add to UTC to obtain the local time. The total offset is comprised of two component parts, the standard time offset and the daylight-saving time offset. The standard time offset is the number of seconds to add to UTC to obtain standard time in the time zone. The daylight-saving time offset is the number of seconds to add to the standard time offset to obtain daylight-saving time (abbreviated DST and sometimes called "daylight time" or "summer time") in the time zone. The usual case for DST (using standard time in winter, DST in summer) has a positive daylight-saving time offset. However, some zones have negative DST offsets, used in winter, with summer using standard time.

Note that the standard and DST offsets for a time zone may change over time as countries have changed DST laws or even their standard time offset.

许可

This class includes data obtained from the CLDR data files under the terms of the Unicode Data Files and Software License. See Unicode CLDR (公共区域设置数据存储库) 了解细节。

另请参阅 QDateTime and QCalendar .

成员类型文档编制

[since 6.5] enum QTimeZone:: 初始化

The type of the simplest lightweight time representations.

This enumeration identifies a type of lightweight time representation to pass to a QTimeZone constructor, where no further data are required. They correspond to the like-named members of Qt::TimeSpec .

常量 描述
QTimeZone::LocalTime 0 This time representation corresponds to the one implicitly used by system functions using time_t and struct tm value to map between local time and UTC time.
QTimeZone::UTC 1 This time representation, Coordinated Universal Time, is the base representation to which civil time is referred in all supported time representations. It is defined by the International Telecommunication Union.

该枚举在 Qt 6.5 引入。

enum QTimeZone:: NameType

The type of time zone name.

常量 描述
QTimeZone::DefaultName 0 The default form of the time zone name, e.g. LongName, ShortName or OffsetName
QTimeZone::LongName 1 The long form of the time zone name, e.g. "Central European Time"
QTimeZone::ShortName 2 The short form of the time zone name, usually an abbreviation, e.g. "CET"
QTimeZone::OffsetName 3 The standard ISO offset form of the time zone name, e.g. "UTC+01:00"

This type is only available when feature timezone is enabled.

QTimeZone:: OffsetDataList

同义词 QList < OffsetData >.

This type is only available when feature timezone is enabled.

enum QTimeZone:: TimeType

The type of time zone time, for example when requesting the name. In time zones that do not apply DST, all three values may return the same result.

常量 描述
QTimeZone::StandardTime 0 The standard time in a time zone, i.e. when Daylight-Saving is not in effect. For example when formatting a display name this will show something like "Pacific Standard Time".
QTimeZone::DaylightTime 1 A time when Daylight-Saving is in effect. For example when formatting a display name this will show something like "Pacific daylight-saving time".
QTimeZone::GenericTime 2 A time which is not specifically Standard or Daylight-Saving time, either an unknown time or a neutral form. For example when formatting a display name this will show something like "Pacific Time".

This type is only available when feature timezone is enabled.

成员函数文档编制

[static, since 6.5] QTimeZone QTimeZone:: fromDurationAheadOfUtc ( std::chrono::seconds offset )

[static, since 6.5] QTimeZone QTimeZone:: fromSecondsAheadOfUtc ( int offset )

Returns a time representation at a fixed offset , in seconds, ahead of UTC.

The offset from UTC must be in the range -16 hours to +16 hours otherwise an invalid time zone will be returned. The returned QTimeZone is a lightweight time representation, not a time zone (backed by system-supplied or standard data).

If the offset is 0, the timeSpec () of the returned instance will be Qt::UTC . Otherwise, if offset is valid, timeSpec () 是 Qt::OffsetFromUTC . An invalid time zone, when returned, has Qt::TimeZone as its timeSpec ().

该函数在 Qt 6.5 引入。

另请参阅 QTimeZone (int), asBackendZone (), fixedSecondsAheadOfUtc (), MinUtcOffsetSecs ,和 MaxUtcOffsetSecs .

[noexcept] QTimeZone:: QTimeZone ()

Create a null/invalid time zone instance.

[noexcept, since 6.5] QTimeZone:: QTimeZone ( QTimeZone::Initialization spec )

Creates a lightweight instance describing UTC or local time.

该函数在 Qt 6.5 引入。

另请参阅 fromSecondsAheadOfUtc (), asBackendZone (), utc (),和 systemTimeZone ().

[explicit] QTimeZone:: QTimeZone ( int offsetSeconds )

Creates a time zone instance with the given offset, offsetSeconds , from UTC.

The offsetSeconds from UTC must be in the range -16 hours to +16 hours otherwise an invalid time zone will be returned.

This constructor is only available when feature timezone is enabled. The returned instance is equivalent to the lightweight time representation QTimeZone::fromSecondsAfterUtc(offsetSeconds) , albeit implemented as a time zone.

另请参阅 MinUtcOffsetSecs , MaxUtcOffsetSecs ,和 id ().

[explicit] QTimeZone:: QTimeZone (const QByteArray & ianaId )

Creates a time zone instance with the requested IANA ID ianaId .

The ID must be one of the available system IDs or a valid UTC-with-offset ID, otherwise an invalid time zone will be returned. For UTC-with-offset IDs, when they are not in fact IANA IDs, the id() of the resulting instance may differ from the ID passed to the constructor.

This constructor is only available when feature timezone is enabled.

另请参阅 availableTimeZoneIds () 和 id ().

QTimeZone:: QTimeZone (const QByteArray & zoneId , int offsetSeconds , const QString & name , const QString & abbreviation , QLocale::Territory territory = QLocale::AnyTerritory, const QString & comment = QString())

Creates a custom time zone instance at fixed offset from UTC.

The returned time zone has an ID of zoneId and an offset from UTC of offsetSeconds name will be the name used by displayName () 为 LongName abbreviation will be used by displayName () 为 ShortName and by abbreviation (), and the optional territory will be used by territory ()。 comment is an optional note that may be displayed in a GUI to assist users in selecting a time zone.

The zoneId 不必 be one of the available system IDs returned by availableTimeZoneIds ()。 offsetSeconds from UTC must be in the range -16 hours to +16 hours.

If the custom time zone does not have a specific territory then set it to the default value of QLocale::AnyTerritory .

This constructor is only available when feature timezone is enabled.

另请参阅 id (), offsetFromUtc (), displayName (), abbreviation (), territory (), comment (), MinUtcOffsetSecs ,和 MaxUtcOffsetSecs .

[noexcept] QTimeZone:: QTimeZone (const QTimeZone & other )

Copy constructor: copy other to this.

[noexcept] QTimeZone:: QTimeZone ( QTimeZone && other )

Move constructor of this from other .

[noexcept] QTimeZone:: ~QTimeZone ()

Destroys the time zone.

QString QTimeZone:: abbreviation (const QDateTime & atDateTime ) const

Returns the time zone abbreviation at the given atDateTime . The abbreviation may change depending on DST or even historical events.

Note that the abbreviation is not guaranteed to be unique to this time zone and should not be used in place of the ID or display name.

This method is only available when feature timezone is enabled.

另请参阅 displayName ().

[since 6.5] QTimeZone QTimeZone:: asBackendZone () const

转换此 QTimeZone to one whose timeSpec () 是 Qt::TimeZone .

In all cases, the result's timeSpec () 是 Qt::TimeZone . When this QTimeZone 's timeSpec () 是 Qt::TimeZone , this QTimeZone itself is returned. If timeSpec () 是 Qt::LocalTime then systemTimeZone () 被返回。

timeSpec () 是 Qt::UTC , QTimeZone::utc () is returned. If it is Qt::OffsetFromUTC then QTimeZone (int) is passed its offset and the result is returned.

When using a lightweight time representation - local time, UTC time or time at a fixed offset from UTC - using methods only supported when feature timezone is enabled may be more expensive than using a corresponding time zone. This method maps a lightweight time representation to a corresponding time zone - that is, an instance based on system-supplied or standard data.

This method is only available when feature timezone is enabled.

该函数在 Qt 6.5 引入。

另请参阅 QTimeZone (QTimeZone::Initialization) and fromSecondsAheadOfUtc ().

[static] QList < QByteArray > QTimeZone:: availableTimeZoneIds ()

Returns a list of all available IANA time zone IDs on this system.

This method is only available when feature timezone is enabled.

注意: the QTimeZone constructor will also accept some UTC-offset IDs that are not in the list returned - it would be impractical to list all possible UTC-offset IDs.

另请参阅 isTimeZoneIdAvailable ().

[static] QList < QByteArray > QTimeZone:: availableTimeZoneIds ( QLocale::Territory territory )

Returns a list of all available IANA time zone IDs for a given territory .

作为特殊情况, territory of AnyTerritory selects those time zones that have no known territorial association, such as UTC. If you require a list of all time zone IDs for all territories then use the standard availableTimeZoneIds() method.

This method is only available when feature timezone is enabled.

另请参阅 isTimeZoneIdAvailable () 和 territory ().

[static] QList < QByteArray > QTimeZone:: availableTimeZoneIds ( int offsetSeconds )

Returns a list of all available IANA time zone IDs with a given standard time offset of offsetSeconds .

Where the given offset is supported, QTimeZone(offsetSeconds).id() is included in the list, even if it is not an IANA ID. This only arises when there is no IANA UTC-offset ID with the given offset.

This method is only available when feature timezone is enabled.

另请参阅 isTimeZoneIdAvailable () 和 QTimeZone (int).

QString QTimeZone:: comment () const

Returns any comment for the time zone.

A comment may be provided by the host platform to assist users in choosing the correct time zone. Depending on the platform this may not be localized.

This method is only available when feature timezone is enabled.

int QTimeZone:: daylightTimeOffset (const QDateTime & atDateTime ) const

Returns the daylight-saving time offset at the given atDateTime , i.e. the number of seconds to add to the standard time offset to obtain the local daylight-saving time.

For example, for the time zone "Europe/Berlin" the DST offset is +3600 seconds. During standard time daylightTimeOffset() will return 0, and when daylight-saving is in effect it will return +3600.

This method is only available when feature timezone is enabled.

另请参阅 offsetFromUtc () 和 standardTimeOffset ().

QString QTimeZone:: displayName (const QDateTime & atDateTime , QTimeZone::NameType nameType = QTimeZone::DefaultName, const QLocale & locale = QLocale()) const

Returns the localized time zone display name at the given atDateTime 为给定 nameType 以给定 locale nameType and locale requested may not be supported on all platforms, in which case the best available option will be returned.

locale is not provided then the application default locale will be used.

The display name may change depending on DST or historical events.

This method is only available when feature timezone is enabled.

另请参阅 abbreviation ().

QString QTimeZone:: displayName ( QTimeZone::TimeType timeType , QTimeZone::NameType nameType = QTimeZone::DefaultName, const QLocale & locale = QLocale()) const

Returns the localized time zone display name for the given timeType and nameType 以给定 locale nameType and locale requested may not be supported on all platforms, in which case the best available option will be returned.

locale is not provided then the application default locale will be used.

Where the time zone display names have changed over time then the most recent names will be used.

This method is only available when feature timezone is enabled.

另请参阅 abbreviation ().

[constexpr noexcept, since 6.5] int QTimeZone:: fixedSecondsAheadOfUtc () const

For a lightweight time representation whose timeSpec () 是 Qt::OffsetFromUTC , this returns the fixed offset from UTC that it describes. For any other time representation it returns 0, even if that time representation does have a constant offset from UTC.

该函数在 Qt 6.5 引入。

[static] QTimeZone QTimeZone:: fromCFTimeZone ( CFTimeZoneRef timeZone )

构造新的 QTimeZone containing a copy of the CFTimeZone timeZone .

另请参阅 toCFTimeZone ().

[static] QTimeZone QTimeZone:: fromNSTimeZone (const NSTimeZone * timeZone )

构造新的 QTimeZone containing a copy of the NSTimeZone timeZone .

另请参阅 toNSTimeZone ().

[static, since 6.4] QTimeZone QTimeZone:: fromStdTimeZonePtr (const int * timeZone )

返回 QTimeZone object representing the same time zone as timeZone . The IANA ID of timeZone must be one of the available system IDs, otherwise an invalid time zone will be returned.

This method is only available when feature timezone is enabled.

该函数在 Qt 6.4 引入。

bool QTimeZone:: hasDaylightTime () const

返回 true if the time zone has practiced daylight-saving at any time.

This method is only available when feature timezone is enabled.

另请参阅 isDaylightTime () 和 daylightTimeOffset ().

bool QTimeZone:: hasTransitions () const

返回 true if the system backend supports obtaining transitions.

Transitions are changes in the time-zone: these happen when DST turns on or off and when authorities alter the offsets for the time-zone.

This method is only available when feature timezone is enabled.

另请参阅 nextTransition (), previousTransition (),和 transitions ().

[static] QByteArray QTimeZone:: ianaIdToWindowsId (const QByteArray & ianaId )

Returns the Windows ID equivalent to the given ianaId .

This method is only available when feature timezone is enabled.

另请参阅 windowsIdToDefaultIanaId () 和 windowsIdToIanaIds ().

QByteArray QTimeZone:: id () const

Returns the IANA ID for the time zone.

IANA IDs are used on all platforms. On Windows these are translated from the Windows ID into the best match IANA ID for the time zone and territory.

If this timezone instance was not constructed from an IANA ID, its ID is determined by how it was constructed. In most cases, the ID passed when constructing the instance is used. (The constructor for a custom zone uses the ID it is passed, which must not be an IANA ID.) There are two exceptions.

  • Instances constructed by passing only a UTC offset in seconds have no ID passed when constructing.
  • The constructor taking only an IANA ID will also accept some UTC-offset IDs that are not in fact IANA IDs: its handling of these is equivalent to passing the corresponding offset in seconds, as for the first exception.

In the two exceptional cases, if there is an IANA UTC-offset zone with the specified offset, the instance constructed uses that IANA zone's ID, even though this may differ from the (non-IANA) UTC-offset ID passed to the constructor. Otherwise, the instance uses an ID synthesized from its offset, with the form UTC±hh:mm:ss, omitting any trailing :00 for zero seconds or minutes. Again, this may differ from the UTC-offset ID passed to the constructor.

This method is only available when feature timezone is enabled.

bool QTimeZone:: isDaylightTime (const QDateTime & atDateTime ) const

返回 true if daylight-saving was in effect at the given atDateTime .

This method is only available when feature timezone is enabled.

另请参阅 hasDaylightTime () 和 daylightTimeOffset ().

[static] bool QTimeZone:: isTimeZoneIdAvailable (const QByteArray & ianaId )

返回 true if a given time zone ianaId is available on this system.

This may include some non-IANA IDs, notably UTC-offset IDs, that are not listed in availableTimeZoneIds ().

This method is only available when feature timezone is enabled.

另请参阅 availableTimeZoneIds ().

[static constexpr noexcept, since 6.5] bool QTimeZone:: isUtcOrFixedOffset ( Qt::TimeSpec spec )

返回 true if spec is Qt::UTC or Qt::OffsetFromUTC .

该函数在 Qt 6.5 引入。

[constexpr noexcept, since 6.5] bool QTimeZone:: isUtcOrFixedOffset () const

返回 true if timeSpec () 是 Qt::UTC or Qt::OffsetFromUTC .

When it is true, the time description does not change over time, such as having seasonal daylight-saving changes, as may happen for local time or a time zone. Knowing this may save the calling code to need for various other checks.

该函数在 Qt 6.5 引入。

bool QTimeZone:: isValid () const

返回 true if this time zone is valid.

QTimeZone::OffsetData QTimeZone:: nextTransition (const QDateTime & afterDateTime ) const

Returns the first time zone Transition after the given afterDateTime . This is most useful when you have a Transition time and wish to find the Transition after it.

If there is no transition after the given afterDateTime then an invalid OffsetData will be returned with an invalid QDateTime as its atUtc .

给定 afterDateTime is exclusive.

This method is only available when feature timezone is enabled.

另请参阅 hasTransitions (), previousTransition (),和 transitions ().

QTimeZone::OffsetData QTimeZone:: offsetData (const QDateTime & forDateTime ) const

Returns the effective offset details at the given forDateTime .

This is the equivalent of calling abbreviation () and all three offset functions individually but is more efficient. If this data is not available for the given datetime, an invalid OffsetData will be returned with an invalid QDateTime as its atUtc .

This method is only available when feature timezone is enabled.

另请参阅 offsetFromUtc (), standardTimeOffset (), daylightTimeOffset (),和 abbreviation ().

int QTimeZone:: offsetFromUtc (const QDateTime & atDateTime ) const

Returns the total effective offset at the given atDateTime , i.e. the number of seconds to add to UTC to obtain the local time. This includes any DST offset that may be in effect, i.e. it is the sum of standardTimeOffset () 和 daylightTimeOffset () for the given datetime.

For example, for the time zone "Europe/Berlin" the standard time offset is +3600 seconds and the DST offset is +3600 seconds. During standard time offsetFromUtc() will return +3600 (UTC+01:00), and during DST it will return +7200 (UTC+02:00).

This method is only available when feature timezone is enabled.

另请参阅 standardTimeOffset () 和 daylightTimeOffset ().

QTimeZone::OffsetData QTimeZone:: previousTransition (const QDateTime & beforeDateTime ) const

Returns the first time zone Transition before the given beforeDateTime . This is most useful when you have a Transition time and wish to find the Transition before it.

If there is no transition before the given beforeDateTime then an invalid OffsetData will be returned with an invalid QDateTime as its atUtc .

给定 beforeDateTime is exclusive.

This method is only available when feature timezone is enabled.

另请参阅 hasTransitions (), nextTransition (),和 transitions ().

int QTimeZone:: standardTimeOffset (const QDateTime & atDateTime ) const

Returns the standard time offset at the given atDateTime , i.e. the number of seconds to add to UTC to obtain the local Standard Time. This excludes any DST offset that may be in effect.

For example, for the time zone "Europe/Berlin" the standard time offset is +3600 seconds. During both standard and DST offsetFromUtc () will return +3600 (UTC+01:00).

This method is only available when feature timezone is enabled.

另请参阅 offsetFromUtc () 和 daylightTimeOffset ().

[noexcept] void QTimeZone:: swap ( QTimeZone & other )

Swaps this time zone instance with other 。此函数非常快且从不失败。

[static] QTimeZone QTimeZone:: systemTimeZone ()

返回 QTimeZone object that describes local system time.

This method is only available when feature timezone is enabled. The returned instance is usually equivalent to the lightweight time representation QTimeZone(QTimeZone::LocalTime) , albeit implemented as a time zone.

The returned object will not change to reflect any subsequent change to the system time zone. It represents the local time that was in effect when asBackendZone () was called. On misconfigured systems, such as those that lack the timezone data relied on by the backend for which Qt was compiled, it may be invalid. In such a case, a warning is output.

另请参阅 utc (), 初始化 , asBackendZone (),和 systemTimeZoneId ().

[static] QByteArray QTimeZone:: systemTimeZoneId ()

Returns the current system time zone IANA ID.

相当于调用 systemTimeZone (). id (), but may bypass some computation to obtain it. Constructing a QTimeZone from the returned byte array will produce the same result as systemTimeZone ().

If the backend is unable to determine the correct system zone, the result is empty. In this case, systemTimeZone (). isValid () is false and a warning is output if either this method of systemTimeZone () 被调用。

If the backend is able to determine the correct system zone but not its name, an empty byte array is returned. For example, on Windows, the system native ID is converted to an IANA ID - if the system ID isn't known to the internal translation code, the result shall be empty. In this case, systemTimeZone (). isValid () shall be true.

This method is only available when feature timezone is enabled.

注意: Prior to Qt 6.7, when the result could not be determined, the misleading result "UTC" was returned.

另请参阅 systemTimeZone ().

[since 6.2] QLocale::Territory QTimeZone:: territory () const

Returns the territory for the time zone.

A return of AnyTerritory means the zone has no known territorial association. In some cases this may be because the zone has no associated territory - for example, UTC - or because the zone is used in several territories - for example, CET. In other cases, the QTimeZone backend may not know which territory the zone is associated with - for example, because it is not the primary zone of the territory in which it is used.

This method is only available when feature timezone is enabled.

该函数在 Qt 6.2 引入。

[constexpr noexcept, since 6.5] Qt::TimeSpec QTimeZone:: timeSpec () const

返回 Qt::TimeSpec identifying the type of time representation.

若结果为 Qt::TimeZone , this time description is a time zone (backed by system-supplied or standard data); otherwise, it is a lightweight time representation. If the result is Qt::LocalTime it describes local time: see Qt::TimeSpec 了解细节。

该函数在 Qt 6.5 引入。

另请参阅 fixedSecondsAheadOfUtc () 和 asBackendZone ().

CFTimeZoneRef QTimeZone:: toCFTimeZone () const

Creates a CFTimeZone from a QTimeZone .

The caller owns the CFTimeZone object and is responsible for releasing it.

另请参阅 fromCFTimeZone ().

NSTimeZone *QTimeZone:: toNSTimeZone () const

Creates an NSTimeZone from a QTimeZone .

The NSTimeZone object is autoreleased.

另请参阅 fromNSTimeZone ().

QTimeZone::OffsetDataList QTimeZone:: 过渡 (const QDateTime & fromDateTime , const QDateTime & toDateTime ) const

Returns a list of all time zone transitions between the given datetimes.

给定 fromDateTime and toDateTime are inclusive. The atUtc member of each entry describes the moment of the transition, at which the offsets and abbreviation given by other members take effect.

This method is only available when feature timezone is enabled.

另请参阅 hasTransitions (), nextTransition (),和 previousTransition ().

[static] QTimeZone QTimeZone:: utc ()

返回 QTimeZone object that describes UTC as a time zone.

This method is only available when feature timezone is enabled. It is equivalent to passing 0 to QTimeZone (int offsetSeconds) and to the lightweight time representation QTimeZone ( QTimeZone::UTC ), albeit implemented as a time zone, unlike the latter.

另请参阅 systemTimeZone (), 初始化 ,和 asBackendZone ().

[static] QByteArray QTimeZone:: windowsIdToDefaultIanaId (const QByteArray & windowsId )

Returns the default IANA ID for a given windowsId .

Because a Windows ID can cover several IANA IDs in several different territories, this function returns the most frequently used IANA ID with no regard for the territory and should thus be used with care. It is usually best to request the default for a specific territory.

This method is only available when feature timezone is enabled.

另请参阅 ianaIdToWindowsId () 和 windowsIdToIanaIds ().

[static] QByteArray QTimeZone:: windowsIdToDefaultIanaId (const QByteArray & windowsId , QLocale::Territory territory )

Returns the default IANA ID for a given windowsId and territory .

Because a Windows ID can cover several IANA IDs within a given territory, the most frequently used IANA ID in that territory is returned.

As a special case, AnyTerritory returns the default of those IANA IDs that have no known territorial association.

This method is only available when feature timezone is enabled.

另请参阅 ianaIdToWindowsId (), windowsIdToIanaIds (),和 territory ().

[static] QList < QByteArray > QTimeZone:: windowsIdToIanaIds (const QByteArray & windowsId )

Returns all the IANA IDs for a given windowsId .

The returned list is sorted alphabetically.

This method is only available when feature timezone is enabled.

另请参阅 ianaIdToWindowsId () 和 windowsIdToDefaultIanaId ().

[static] QList < QByteArray > QTimeZone:: windowsIdToIanaIds (const QByteArray & windowsId , QLocale::Territory territory )

Returns all the IANA IDs for a given windowsId and territory .

As a special case, AnyTerritory selects those IANA IDs that have no known territorial association.

The returned list is in order of frequency of usage, i.e. larger zones within a territory are listed first.

This method is only available when feature timezone is enabled.

另请参阅 ianaIdToWindowsId (), windowsIdToDefaultIanaId (),和 territory ().

QTimeZone &QTimeZone:: operator= (const QTimeZone & other )

Assignment operator, assign other to this.

[noexcept] QTimeZone &QTimeZone:: operator= ( QTimeZone && other )

移动赋值 other 到此 QTimeZone instance, transferring the ownership of its data to this instance.

成员变量文档编制

const int QTimeZone:: MaxUtcOffsetSecs

Timezone offsets from UTC are expected to be no higher than this.

The highest UTC offset of any early 21st century timezone is +14 hours (Christmas Island, Kiribati, Kiritimati), or 14 hours east of Greenwich.

Historically, before 1867, when Russia sold Alaska to America, Alaska used the same date as Russia, so had offsets over 15 hours east of Greenwich. As Alaska was using local solar mean time, its offsets varied, but all were less than 16 hours east of Greenwich.

另请参阅 MinUtcOffsetSecs .

const int QTimeZone:: MinUtcOffsetSecs

Timezone offsets from UTC are expected to be no lower than this.

The lowest UTC offset of any early 21st century timezone is -12 hours (Baker Island, USA), or 12 hours west of Greenwich.

Historically, until 1844, The Philippines (then controlled by Spain) used the same date as Spain's American holdings, so had offsets close to 16 hours west of Greenwich. As The Philippines was using local solar mean time, it is possible some outlying territory of it may have been operating at more than 16 hours west of Greenwich, but no early 21st century timezone traces its history back to such an extreme.

另请参阅 MaxUtcOffsetSecs .

相关非成员

[noexcept] bool operator!= (const QTimeZone & lhs , const QTimeZone & rhs )

返回 true if lhs time zone is not equal to the rhs time zone.

Two representations are different if they are internally described differently, even if they agree in their representation of all moments of time. In particular, a lightweight time representation may coincide with a time zone but the two will not be equal.

[noexcept] bool operator== (const QTimeZone & lhs , const QTimeZone & rhs )

返回 true if lhs time zone is equal to the rhs time zone.

Two representations are different if they are internally described differently, even if they agree in their representation of all moments of time. In particular, a lightweight time representation may coincide with a time zone but the two will not be equal.