Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtCore\reentrant More...
#include <qdatetime.h>
Public Types | |
enum class | TransitionResolution { Reject = 0 , RelativeToBefore , RelativeToAfter , PreferBefore , PreferAfter , PreferStandard , PreferDaylightSaving , LegacyBehavior = RelativeToBefore } |
enum class | YearRange : qint32 { First = -292275056 , Last = +292278994 } |
Public Member Functions | |
QDateTime () noexcept | |
Constructs a null datetime, nominally using local time. | |
QDateTime (QDate date, QTime time, const QTimeZone &timeZone, TransitionResolution resolve=TransitionResolution::LegacyBehavior) | |
QDateTime (QDate date, QTime time, TransitionResolution resolve=TransitionResolution::LegacyBehavior) | |
QDateTime (const QDateTime &other) noexcept | |
Constructs a copy of the other datetime. | |
QDateTime (QDateTime &&other) noexcept | |
~QDateTime () | |
Destroys the datetime. | |
QDateTime & | operator= (const QDateTime &other) noexcept |
Copies the other datetime into this and returns this copy. | |
void | swap (QDateTime &other) noexcept |
bool | isNull () const |
Returns true if both the date and the time are null; otherwise returns false . | |
bool | isValid () const |
Returns true if this datetime represents a definite moment, otherwise false . | |
QDate | date () const |
Returns the date part of the datetime. | |
QTime | time () const |
Returns the time part of the datetime. | |
Qt::TimeSpec | timeSpec () const |
Returns the time specification of the datetime. | |
int | offsetFromUtc () const |
QTimeZone | timeRepresentation () const |
QString | timeZoneAbbreviation () const |
bool | isDaylightTime () const |
qint64 | toMSecsSinceEpoch () const |
qint64 | toSecsSinceEpoch () const |
void | setDate (QDate date, TransitionResolution resolve=TransitionResolution::LegacyBehavior) |
Sets the date part of this datetime to date. | |
void | setTime (QTime time, TransitionResolution resolve=TransitionResolution::LegacyBehavior) |
Sets the time part of this datetime to time. | |
void | setTimeZone (const QTimeZone &toZone, TransitionResolution resolve=TransitionResolution::LegacyBehavior) |
void | setMSecsSinceEpoch (qint64 msecs) |
void | setSecsSinceEpoch (qint64 secs) |
QDateTime | addDays (qint64 days) const |
Returns a QDateTime object containing a datetime ndays days later than the datetime of this object (or earlier if ndays is negative). | |
QDateTime | addMonths (int months) const |
Returns a QDateTime object containing a datetime nmonths months later than the datetime of this object (or earlier if nmonths is negative). | |
QDateTime | addYears (int years) const |
Returns a QDateTime object containing a datetime nyears years later than the datetime of this object (or earlier if nyears is negative). | |
QDateTime | addSecs (qint64 secs) const |
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or earlier if s is negative). | |
QDateTime | addMSecs (qint64 msecs) const |
Returns a QDateTime object containing a datetime msecs milliseconds later than the datetime of this object (or earlier if msecs is negative). | |
QDateTime | addDuration (std::chrono::milliseconds msecs) const |
QDateTime | toLocalTime () const |
Returns a copy of this datetime converted to local time. | |
QDateTime | toUTC () const |
Returns a copy of this datetime converted to UTC. | |
QDateTime | toOffsetFromUtc (int offsetSeconds) const |
QDateTime | toTimeZone (const QTimeZone &toZone) const |
qint64 | daysTo (const QDateTime &) const |
Returns the number of days from this datetime to the other datetime. | |
qint64 | secsTo (const QDateTime &) const |
Returns the number of seconds from this datetime to the other datetime. | |
qint64 | msecsTo (const QDateTime &) const |
Returns the number of milliseconds from this datetime to the other datetime. | |
QDateTime & | operator+= (std::chrono::milliseconds duration) |
QDateTime & | operator-= (std::chrono::milliseconds duration) |
Static Public Member Functions | |
static QDateTime | currentDateTime (const QTimeZone &zone) |
static QDateTime | currentDateTime () |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static QDateTime | currentDateTimeUtc () |
static QDateTime | fromMSecsSinceEpoch (qint64 msecs, const QTimeZone &timeZone) |
static QDateTime | fromSecsSinceEpoch (qint64 secs, const QTimeZone &timeZone) |
static QDateTime | fromMSecsSinceEpoch (qint64 msecs) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static QDateTime | fromSecsSinceEpoch (qint64 secs) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
static qint64 | currentMSecsSinceEpoch () noexcept |
static qint64 | currentSecsSinceEpoch () noexcept |
static QDateTime | fromStdTimePoint (std::chrono::time_point< std::chrono::system_clock, std::chrono::milliseconds > time) |
Friends | |
class | QDateTimePrivate |
std::chrono::milliseconds | operator- (const QDateTime &lhs, const QDateTime &rhs) |
QDateTime | operator+ (const QDateTime &dateTime, std::chrono::milliseconds duration) |
QDateTime | operator+ (std::chrono::milliseconds duration, const QDateTime &dateTime) |
QDateTime | operator- (const QDateTime &dateTime, std::chrono::milliseconds duration) |
bool | comparesEqual (const QDateTime &lhs, const QDateTime &rhs) |
Q_CORE_EXPORT Qt::weak_ordering | compareThreeWay (const QDateTime &lhs, const QDateTime &rhs) |
Q_CORE_EXPORT QDataStream & | operator<< (QDataStream &, const QDateTime &) |
Writes dateTime to the out stream. | |
Q_CORE_EXPORT QDataStream & | operator>> (QDataStream &, QDateTime &) |
Reads a datetime from the stream in into dateTime. | |
\inmodule QtCore
\reentrant
The QDateTime class provides date and time functions.
\compares weak
A QDateTime object encodes a calendar date and a clock time (a "datetime") in accordance with a time representation. It combines features of the QDate and QTime classes. It can read the current datetime from the system clock. It provides functions for comparing datetimes and for manipulating a datetime by adding a number of seconds, days, months, or years.
QDateTime can describe datetimes with respect to \l{Qt::LocalTime}{local time}, to \l{Qt::UTC}{UTC}, to a specified \l{Qt::OffsetFromUTC}{offset from UTC} or to a specified \l{Qt::TimeZone}{time zone}. Each of these time representations can be encapsulated in a suitable instance of the QTimeZone class. For example, a time zone of "Europe/Berlin" will apply the daylight-saving rules as used in Germany. In contrast, a fixed offset from UTC of +3600 seconds is one hour ahead of UTC (usually written in ISO standard notation as "UTC+01:00"), with no daylight-saving complications. When using either local time or a specified time zone, time-zone transitions (see \l {Timezone transitions}{below}) are taken into account. A QDateTime's timeSpec() will tell you which of the four types of time representation is in use; its timeRepresentation() provides a full description of that time representation, as a QTimeZone.
A QDateTime object is typically created either by giving a date and time explicitly in the constructor, or by using a static function such as currentDateTime() or fromMSecsSinceEpoch(). The date and time can be changed with setDate() and setTime(). A datetime can also be set using the setMSecsSinceEpoch() function that takes the time, in milliseconds, since the start, in UTC, of the year 1970. The fromString() function returns a QDateTime, given a string and a date format used to interpret the date within the string.
QDateTime::currentDateTime() returns a QDateTime that expresses the current date and time with respect to a specific time representation, such as local time (its default). QDateTime::currentDateTimeUtc() returns a QDateTime that expresses the current date and time with respect to UTC; it is equivalent to {QDateTime::currentDateTime(QTimeZone::UTC)}
.
The date() and time() functions provide access to the date and time parts of the datetime. The same information is provided in textual format by the toString() function.
QDateTime provides a full set of operators to compare two QDateTime objects, where smaller means earlier and larger means later.
You can increment (or decrement) a datetime by a given number of milliseconds using addMSecs(), seconds using addSecs(), or days using addDays(). Similarly, you can use addMonths() and addYears(). The daysTo() function returns the number of days between two datetimes, secsTo() returns the number of seconds between two datetimes, and msecsTo() returns the number of milliseconds between two datetimes. These operations are aware of daylight-saving time (DST) and other time-zone transitions, where applicable.
Use toTimeZone() to re-express a datetime in terms of a different time representation. By passing a lightweight QTimeZone that represents local time, UTC or a fixed offset from UTC, you can convert the datetime to use the corresponding time representation; or you can pass a full time zone (whose \l {QTimeZone::timeSpec()}{timeSpec()} is {Qt::TimeZone}
) to use that instead.
Definition at line 289 of file qdatetime.h.
|
strong |
This enumeration is used to resolve datetime combinations which fall in \l {Timezone transitions}.
When constructing a datetime, specified in terms of local time or a time-zone that has daylight-saving time, or revising one with setDate(), setTime() or setTimeZone(), the given parameters may imply a time representation that either has no meaning or has two meanings in the zone. Such time representations are described as being in the transition. In either case, we can simply return an invalid datetime, to indicate that the operation is ill-defined. In the ambiguous case, we can alternatively select one of the two times that could be meant. When there is no meaning, we can select a time either side of it that might plausibly have been meant. For example, when advancing from an earlier time, we can select the time after the transition that is actually the specified amount of time after the earlier time in question. The options specified here configure how such selection is performed.
\value Reject Treat any time in a transition as invalid. Either it really is, or it is ambiguous. \value RelativeToBefore Selects a time as if stepping forward from a time before the transition. This interprets the requested time using the offset in effect before the transition and, if necessary, converts the result to the offset in effect at the resulting time. \value RelativeToAfter Select a time as if stepping backward from a time after the transition. This interprets the requested time using the offset in effect after the transition and, if necessary, converts the result to the offset in effect at the resulting time. \value PreferBefore Selects a time before the transition, \value PreferAfter Selects a time after the transition. \value PreferStandard Selects a time on the standard time side of the transition. \value PreferDaylightSaving Selects a time on the daylight-saving-time side of the transition. \value LegacyBehavior An alias for RelativeToBefore, which is used as default for TransitionResolution parameters, as this most closely matches the behavior prior to Qt 6.7.
For \l addDays(), \l addMonths() or \l addYears(), the behavior is and (mostly) was to use RelativeToBefore
if adding a positive adjustment and RelativeToAfter
if adding a negative adjustment.
The following tables illustrate how a QDateTime constructor resolves a request for 02:30 on a day when local time has a transition between 02:00 and 03:00, with a nominal standard time LST and daylight-saving time LDT on the two sides, in the various possible cases. The transition type may be to skip an hour or repeat it. The type of transition and value of a parameter resolve
determine which actual time on the given date is selected. First, the common case of positive daylight-saving, where:
\table \header
resolve
Second, the case for negative daylight-saving, using LDT in winter and skipping an hour to transition to LST in summer, then repeating an hour at the transition back to winter:
\table \row
Reject can be used to prompt relevant QDateTime APIs to return an invalid datetime object so that your code can deal with transitions for itself, for example by alerting a user to the fact that the datetime they have selected is in a transition interval, to offer them the opportunity to resolve a conflict or ambiguity. Code using this may well find the other options above useful to determine relevant information to use in its own (or the user's) resolution. If the start or end of the transition, or the moment of the transition itself, is the right resolution, QTimeZone's transition APIs can be used to obtain that information. You can determine whether the transition is a repeated or skipped interval by using \l secsTo() to measure the actual time between noon on the previous and following days. The result will be less than 48 hours for a skipped interval (such as a spring-forward) and more than 48 hours for a repeated interval (such as a fall-back).
Enumerator | |
---|---|
Reject | |
RelativeToBefore | |
RelativeToAfter | |
PreferBefore | |
PreferAfter | |
PreferStandard | |
PreferDaylightSaving | |
LegacyBehavior |
Definition at line 348 of file qdatetime.h.
|
strong |
This enumerated type describes the range of years (in the Gregorian calendar) representable by QDateTime:
\value First The later parts of this year are representable \value Last The earlier parts of this year are representable
All dates strictly between these two years are also representable. Note, however, that the Gregorian Calendar has no year zero.
Enumerator | |
---|---|
First | |
Last |
Definition at line 623 of file qdatetime.h.
|
noexcept |
Constructs a null datetime, nominally using local time.
A null datetime is invalid, since its date and time are invalid.
Definition at line 3950 of file qdatetime.cpp.
QDateTime::QDateTime | ( | QDate | date, |
QTime | time, | ||
const QTimeZone & | timeZone, | ||
TransitionResolution | resolve = TransitionResolution::LegacyBehavior ) |
\since 5.2 Constructs a datetime with the given \a date and \a time, using the time representation described by \a timeZone. If \a date is valid and \a time is not, the time will be set to midnight. If \a timeZone is invalid then the datetime will be invalid. If \a date and \a time describe a moment close to a transition for \a timeZone, \a resolve controls how that situation is resolved.
! [pre-resolve-note]
Definition at line 4004 of file qdatetime.cpp.
QDateTime::QDateTime | ( | QDate | date, |
QTime | time, | ||
TransitionResolution | resolve = TransitionResolution::LegacyBehavior ) |
Constructs a datetime with the given date and time, using local time.
If date is valid and time is not, midnight will be used as the time. If date and time describe a moment close to a transition for local time, resolve controls how that situation is resolved.
pre-resolve-note
Definition at line 4022 of file qdatetime.cpp.
|
noexcept |
Constructs a copy of the other datetime.
Definition at line 4030 of file qdatetime.cpp.
|
noexcept |
Definition at line 4040 of file qdatetime.cpp.
QDateTime::~QDateTime | ( | ) |
Destroys the datetime.
Definition at line 4048 of file qdatetime.cpp.
Returns a QDateTime object containing a datetime ndays days later than the datetime of this object (or earlier if ndays is negative).
If the timeSpec() is Qt::LocalTime or Qt::TimeZone and the resulting date and time fall in the Standard Time to Daylight-Saving Time transition hour then the result will be just beyond this gap, in the direction of change. If the transition is at 2am and the clock goes forward to 3am, the result of aiming between 2am and 3am will be adjusted to fall before 2am (if {ndays < 0}) or after 3am (otherwise).
Definition at line 4806 of file qdatetime.cpp.
|
inlinenodiscard |
Returns a QDateTime object containing a datetime msecs milliseconds later than the datetime of this object (or earlier if msecs is negative).
If this datetime is invalid, an invalid datetime will be returned.
{std::chrono::months} or
{std::chrono::years} does not yield the same result obtained by using addMonths() or addYears(). The former are fixed durations, calculated in relation to the solar year; the latter use the Gregorian calendar definitions of months/years.Definition at line 432 of file qdatetime.h.
|
nodiscard |
Returns a QDateTime object containing a datetime nmonths months later than the datetime of this object (or earlier if nmonths is negative).
If the timeSpec() is Qt::LocalTime or Qt::TimeZone and the resulting date and time fall in the Standard Time to Daylight-Saving Time transition hour then the result will be just beyond this gap, in the direction of change. If the transition is at 2am and the clock goes forward to 3am, the result of aiming between 2am and 3am will be adjusted to fall before 2am (if {nmonths < 0}) or after 3am (otherwise).
Definition at line 4832 of file qdatetime.cpp.
Returns a QDateTime object containing a datetime msecs milliseconds later than the datetime of this object (or earlier if msecs is negative).
If this datetime is invalid, an invalid datetime will be returned.
Definition at line 4896 of file qdatetime.cpp.
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or earlier if s is negative).
If this datetime is invalid, an invalid datetime will be returned.
Definition at line 4879 of file qdatetime.cpp.
|
nodiscard |
Returns a QDateTime object containing a datetime nyears years later than the datetime of this object (or earlier if nyears is negative).
If the timeSpec() is Qt::LocalTime or Qt::TimeZone and the resulting date and time fall in the Standard Time to Daylight-Saving Time transition hour then the result will be just beyond this gap, in the direction of change. If the transition is at 2am and the clock goes forward to 3am, the result of aiming between 2am and 3am will be adjusted to fall before 2am (if {nyears < 0}) or after 3am (otherwise).
Definition at line 4858 of file qdatetime.cpp.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 5316 of file qdatetime.cpp.
Returns the system clock's current datetime, using the time representation described by zone. If zone is omitted, local time is used.
|
static |
Equivalent to {currentDateTime(QTimeZone::UTC)}.
Definition at line 5331 of file qdatetime.cpp.
|
staticnoexcept |
Returns the current number of milliseconds since the start, in UTC, of the year 1970.
This number is like the POSIX time_t variable, but expressed in milliseconds instead of seconds.
|
staticnoexcept |
Returns the number of seconds since the start, in UTC, of the year 1970.
This number is like the POSIX time_t variable.
QDate QDateTime::date | ( | ) | const |
Returns the date part of the datetime.
Definition at line 4105 of file qdatetime.cpp.
Returns the number of days from this datetime to the other datetime.
The number of days is counted as the number of times midnight is reached between this datetime to the other datetime. This means that a 10 minute difference from 23:55 to 0:05 the next day counts as one day.
If the other datetime is earlier than this datetime, the value returned is negative.
Example:
Definition at line 4963 of file qdatetime.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 5642 of file qdatetime.cpp.
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 timeZone. The default time representation is local time.
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.
Definition at line 5630 of file qdatetime.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 5672 of file qdatetime.cpp.
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 timeZone. The default time representation is local time.
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.
Definition at line 5660 of file qdatetime.cpp.
|
static |
Constructs a datetime representing the same point in time as time, using Qt::UTC as its time representation.
The clock of time must be compatible with {std::chrono::system_clock}; in particular, a conversion supported by
{std::chrono::clock_cast} must exist. After the conversion, the duration type of the result must be convertible to
{std::chrono::milliseconds}.
If this is not the case, the caller must perform the necessary clock conversion towards {std::chrono::system_clock} and the necessary conversion of the duration type (cast/round/floor/ceil/...) so that the input to this function satisfies the constraints above.
Constructs a datetime representing the same point in time as time, using Qt::UTC as its time representation.
Constructs a datetime whose date and time are the number of milliseconds represented by time, counted since 1970-01-01T00:00:00.000 in local time (Qt::LocalTime).
Definition at line 5390 of file qdatetime.cpp.
bool QDateTime::isDaylightTime | ( | ) | const |
Returns if this datetime falls in Daylight-Saving Time.
If the Qt::TimeSpec is not Qt::LocalTime or Qt::TimeZone then will always return false.
Definition at line 4282 of file qdatetime.cpp.
bool QDateTime::isNull | ( | ) | const |
Returns true
if both the date and the time are null; otherwise returns false
.
A null datetime is invalid.
Definition at line 4074 of file qdatetime.cpp.
bool QDateTime::isValid | ( | ) | const |
Returns true
if this datetime represents a definite moment, otherwise false
.
A datetime is valid if both its date and its time are valid and the time representation used gives a valid meaning to their combination. When the time representation is a specific time-zone or local time, there may be times on some dates that the zone skips in its representation, as when a daylight-saving transition skips an hour (typically during a night in spring). For example, if DST ends at 2am with the clock advancing to 3am, then datetimes from 02:00:00 to 02:59:59.999 on that day are invalid.
Definition at line 4094 of file qdatetime.cpp.
Returns the number of milliseconds from this datetime to the other datetime.
If the other datetime is earlier than this datetime, the value returned is negative.
Before performing the comparison, the two datetimes are converted to Qt::UTC to ensure that the result is correct if daylight-saving (DST) applies to one of the two datetimes and but not the other.
Returns 0 if either datetime is invalid.
Definition at line 5004 of file qdatetime.cpp.
int QDateTime::offsetFromUtc | ( | ) | const |
Returns this datetime's Offset From UTC in seconds.
The result depends on timeSpec(): \list
Qt::UTC
The offset is 0. Qt::OffsetFromUTC
The offset is the value originally set. Qt::LocalTime
The local time's offset from UTC is returned. Qt::TimeZone
The offset used by the time-zone is returned. \endlistFor the last two, the offset at this date and time will be returned, taking account of Daylight-Saving Offset. The offset is the difference between the local time or time in the given time-zone and UTC time; it is positive in time-zones ahead of UTC (East of The Prime Meridian), negative for those behind UTC (West of The Prime Meridian).
Definition at line 4200 of file qdatetime.cpp.
|
inline |
Modifies this datetime object by adding the given duration. The updated object will be later if duration is positive, or earlier if it is negative.
If this datetime is invalid, this function has no effect.
Returns a reference to this datetime object.
Definition at line 604 of file qdatetime.h.
|
inline |
Modifies this datetime object by subtracting the given duration. The updated object will be earlier if duration is positive, or later if it is negative.
If this datetime is invalid, this function has no effect.
Returns a reference to this datetime object.
Definition at line 615 of file qdatetime.h.
Copies the other datetime into this and returns this copy.
Definition at line 4056 of file qdatetime.cpp.
Returns the number of seconds from this datetime to the other datetime.
If the other datetime is earlier than this datetime, the value returned is negative.
Before performing the comparison, the two datetimes are converted to Qt::UTC to ensure that the result is correct if daylight-saving (DST) applies to one of the two datetimes but not the other.
Returns 0 if either datetime is invalid.
Example:
Definition at line 4985 of file qdatetime.cpp.
void QDateTime::setDate | ( | QDate | date, |
TransitionResolution | resolve = TransitionResolution::LegacyBehavior ) |
Sets the date part of this datetime to date.
If no time is set yet, it is set to midnight. If date is invalid, this QDateTime becomes invalid.
If date and time() describe a moment close to a transition for this datetime's time representation, resolve controls how that situation is resolved.
pre-resolve-note
Definition at line 4329 of file qdatetime.cpp.
Sets the datetime to represent a moment a given number, msecs, of milliseconds after the start, in UTC, of the year 1970.
On systems that do not support time zones, this function will behave as if local time were Qt::UTC.
Note that passing the minimum of qint64
({std::numeric_limits<qint64>::min()}) to msecs will result in undefined behavior.
Definition at line 4524 of file qdatetime.cpp.
Sets the datetime to represent a moment a given number, secs, of seconds after the start, in UTC, of the year 1970.
On systems that do not support time zones, this function will behave as if local time were Qt::UTC.
Definition at line 4586 of file qdatetime.cpp.
void QDateTime::setTime | ( | QTime | time, |
TransitionResolution | resolve = TransitionResolution::LegacyBehavior ) |
Sets the time part of this datetime to time.
If time is not valid, this function sets it to midnight. Therefore, it's possible to clear any set time in a QDateTime by setting it to a default QTime:
If date() and time describe a moment close to a transition for this datetime's time representation, resolve controls how that situation is resolved.
pre-resolve-note
Definition at line 4354 of file qdatetime.cpp.
void QDateTime::setTimeZone | ( | const QTimeZone & | toZone, |
TransitionResolution | resolve = TransitionResolution::LegacyBehavior ) |
Sets the time zone used in this datetime to toZone.
The datetime may refer to a different point in time. It uses the time representation of toZone, which may change the meaning of its unchanged date() and time().
If toZone is invalid then the datetime will be invalid. Otherwise, this datetime's timeSpec() after the call will match {toZone.timeSpec()}.
If date() and time() describe a moment close to a transition for toZone, resolve controls how that situation is resolved.
pre-resolve-note
Definition at line 4428 of file qdatetime.cpp.
Definition at line 379 of file qdatetime.h.
QTime QDateTime::time | ( | ) | const |
Returns the time part of the datetime.
Definition at line 4116 of file qdatetime.cpp.
QTimeZone QDateTime::timeRepresentation | ( | ) | const |
The timeSpec() of the returned QTimeZone will coincide with that of this datetime; if it is not Qt::TimeZone then the returned QTimeZone is a time representation. When their timeSpec() is Qt::OffsetFromUTC, the returned QTimeZone's fixedSecondsAheadOfUtc() supplies the offset. When timeSpec() is Qt::TimeZone, the QTimeZone object itself is the full representation of that time zone.
Definition at line 4151 of file qdatetime.cpp.
Qt::TimeSpec QDateTime::timeSpec | ( | ) | const |
Returns the time specification of the datetime.
This classifies its time representation as local time, UTC, a fixed offset from UTC (without indicating the offset) or a time zone (without giving the details of that time zone). Equivalent to {timeRepresentation().timeSpec()}.
Definition at line 4132 of file qdatetime.cpp.
QString QDateTime::timeZoneAbbreviation | ( | ) | const |
Returns the Time Zone Abbreviation for this datetime.
The returned string depends on timeSpec():
\list
Definition at line 4241 of file qdatetime.cpp.
QDateTime QDateTime::toLocalTime | ( | ) | const |
Returns a copy of this datetime converted to local time.
The result represents the same moment in time as, and is equal to, this datetime.
Example:
Definition at line 5137 of file qdatetime.cpp.
qint64 QDateTime::toMSecsSinceEpoch | ( | ) | const |
Returns the datetime as a number of milliseconds after the start, in UTC, of the year 1970.
On systems that do not support time zones, this function will behave as if local time were Qt::UTC.
The behavior for this function is undefined if the datetime stored in this object is not valid. However, for all valid dates, this function returns a unique value.
Definition at line 4448 of file qdatetime.cpp.
QDateTime QDateTime::toOffsetFromUtc | ( | int | offsetSeconds | ) | const |
Returns a copy of this datetime converted to a spec of Qt::OffsetFromUTC with the given offsetSeconds. Equivalent to {toTimeZone(QTimeZone::fromSecondsAheadOfUtc(offsetSeconds))}.
If the offsetSeconds equals 0 then a UTC datetime will be returned.
The result represents the same moment in time as, and is equal to, this datetime.
Definition at line 5121 of file qdatetime.cpp.
qint64 QDateTime::toSecsSinceEpoch | ( | ) | const |
Returns the datetime as a number of seconds after the start, in UTC, of the year 1970.
On systems that do not support time zones, this function will behave as if local time were Qt::UTC.
The behavior for this function is undefined if the datetime stored in this object is not valid. However, for all valid dates, this function returns a unique value.
Definition at line 4504 of file qdatetime.cpp.
Returns a copy of this datetime converted to the given timeZone.
The result represents the same moment in time as, and is equal to, this datetime.
The result describes the moment in time in terms of timeZone's time representation. For example:
If timeZone is invalid then the datetime will be invalid. Otherwise the returned datetime's timeSpec() will match {timeZone.timeSpec()}.
Definition at line 5176 of file qdatetime.cpp.
QDateTime QDateTime::toUTC | ( | ) | const |
Returns a copy of this datetime converted to UTC.
The result represents the same moment in time as, and is equal to, this datetime.
Example:
Definition at line 5153 of file qdatetime.cpp.
Definition at line 634 of file qdatetime.h.
|
friend |
Definition at line 5244 of file qdatetime.cpp.
Definition at line 594 of file qdatetime.h.
Returns a QDateTime object containing a datetime duration milliseconds later than dateTime (or earlier if duration is negative).
If dateTime is invalid, an invalid datetime will be returned.
Definition at line 599 of file qdatetime.h.
Returns a QDateTime object containing a datetime duration milliseconds earlier than dateTime (or later if duration is negative).
If dateTime is invalid, an invalid datetime will be returned.
Definition at line 610 of file qdatetime.h.
Returns the number of milliseconds between lhs and rhs. If lhs is earlier than rhs, the result will be negative.
Returns 0 if either datetime is invalid.
Definition at line 589 of file qdatetime.h.
|
friend |
Writes dateTime to the out stream.
Definition at line 6081 of file qdatetime.cpp.
|
friend |
Reads a datetime from the stream in into dateTime.
Definition at line 6146 of file qdatetime.cpp.
|
friend |
Definition at line 630 of file qdatetime.h.