![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore\reentrant More...
#include <qdatetime.h>
Public Types | |
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) | |
QDateTime (QDate date, QTime time) | |
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) |
Sets the date part of this datetime to date. | |
void | setTime (QTime time) |
Sets the time part of this datetime to time. | |
void | setTimeZone (const QTimeZone &toZone) |
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) |
static QDateTime | fromSecsSinceEpoch (qint64 secs) |
static qint64 | currentMSecsSinceEpoch () noexcept |
static qint64 | currentSecsSinceEpoch () noexcept |
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 | operator== (const QDateTime &lhs, const QDateTime &rhs) |
Returns true if lhs is the same as rhs; otherwise returns false . | |
bool | operator!= (const QDateTime &lhs, const QDateTime &rhs) |
Returns true if lhs is different from rhs; otherwise returns false . | |
bool | operator< (const QDateTime &lhs, const QDateTime &rhs) |
Returns true if lhs is earlier than rhs; otherwise returns false . | |
bool | operator<= (const QDateTime &lhs, const QDateTime &rhs) |
Returns true if lhs is earlier than or equal to rhs; otherwise returns false . | |
bool | operator> (const QDateTime &lhs, const QDateTime &rhs) |
Returns true if lhs is later than rhs; otherwise returns false . | |
bool | operator>= (const QDateTime &lhs, const QDateTime &rhs) |
Returns true if lhs is later than or equal to rhs; otherwise returns false . | |
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. | |
Related Symbols | |
(Note that these are not member symbols.) | |
QDataStream & | operator<< (QDataStream &out, const QDateTime &dateTime) |
Writes dateTime to the out stream. | |
QDataStream & | operator>> (QDataStream &in, QDateTime &dateTime) |
Reads a datetime from the stream in into dateTime. | |
\inmodule QtCore
\reentrant
The QDateTime class provides date and time functions.
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 {Daylight-Saving Time (DST)}{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 representation 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 256 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 517 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 3473 of file qdatetime.cpp.
References Data.
Referenced by addDays(), addMonths(), addMSecs(), addSecs(), and addYears().
Constructs a datetime with the given date and time, using the time representation described by timeZone.
If date is valid and time is not, the time will be set to midnight. If timeZone is invalid then the datetime will be invalid.
Definition at line 3519 of file qdatetime.cpp.
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.
Definition at line 3532 of file qdatetime.cpp.
|
noexcept |
Constructs a copy of the other datetime.
Definition at line 3540 of file qdatetime.cpp.
|
noexcept |
Definition at line 3550 of file qdatetime.cpp.
QDateTime::~QDateTime | ( | ) |
Destroys the datetime.
Definition at line 3558 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 adjusted accordingly, i.e. if the transition is at 2am and the clock goes forward to 3am and the result falls between 2am and 3am then the result will be adjusted to fall after 3am.
Definition at line 4273 of file qdatetime.cpp.
References QDateTime(), getDateTime(), isNull(), and massageAdjustedDateTime().
Referenced by jobHoldToString().
|
inline |
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 368 of file qdatetime.h.
QDateTime QDateTime::addMonths | ( | int | nmonths | ) | const |
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 adjusted accordingly, i.e. if the transition is at 2am and the clock goes forward to 3am and the result falls between 2am and 3am then the result will be adjusted to fall after 3am.
Definition at line 4298 of file qdatetime.cpp.
References QDateTime(), getDateTime(), isNull(), and massageAdjustedDateTime().
Referenced by QDateTimeParser::parse().
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 4361 of file qdatetime.cpp.
References QDateTime(), getMSecs(), getSpec(), isValid(), Qt::LocalTime, msecsCanBeSmall(), Qt::OffsetFromUTC, qAddOverflow(), setMSecsSinceEpoch(), Qt::TimeZone, toMSecsSinceEpoch(), Qt::UTC, and QDateTimePrivate::ValidityMask.
Referenced by addSecs(), and QQmlJS::Dom::DomEnvironment::finishLoadingDependencies().
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 4344 of file qdatetime.cpp.
References QDateTime(), addMSecs(), and qMulOverflow().
Referenced by QNetworkReplyHttpImplPrivate::fetchCacheMetaData(), QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(), QHstsHeaderParser::parse(), QDateTimeParser::parse(), and parseDateString().
QDateTime QDateTime::addYears | ( | int | nyears | ) | const |
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 adjusted accordingly, i.e. if the transition is at 2am and the clock goes forward to 3am and the result falls between 2am and 3am then the result will be adjusted to fall after 3am.
Definition at line 4323 of file qdatetime.cpp.
References QDateTime(), getDateTime(), isNull(), and massageAdjustedDateTime().
|
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 4788 of file qdatetime.cpp.
References currentDateTime(), and QTimeZone::LocalTime.
Referenced by QCtfLibImpl::QCtfLibImpl(), QZipWriterPrivate::addEntry(), currentDateTime(), currentDateTimeUtc(), QCalendarBackend::dateTimeToString(), QmlLsp::QmlLintSuggestions::diagnose(), QQmlPreviewFileEngine::fileTime(), ApplicationData::getCurrentDateTime(), jobHoldToString(), main(), QGstreamerImageCapture::probeBuffer(), QGeoAreaMonitorPolling::requestUpdate(), QJUnitTestLogger::startLogging(), and QGeoAreaMonitorPolling::startMonitoring().
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 4803 of file qdatetime.cpp.
References currentDateTime(), and QTimeZone::UTC.
Referenced by QQmlJS::Dom::addExternalItem(), QQmlJS::Dom::LoadInfo::advanceLoad(), QNetworkCookieJar::cookiesForUrl(), currentTime(), QQmlJS::Dom::envCallbackForFile(), QQmlJS::Dom::DomUniverse::execQueue(), QNetworkReplyHttpImplPrivate::fetchCacheMetaData(), QQmlJS::Dom::DomEnvironment::finishLoadingDependencies(), QQmlJS::Dom::QmldirFile::fromPathAndCode(), QNetworkCookieJar::insertCookie(), QLockFilePrivate::isApparentlyStale(), QHstsPolicy::isExpired(), QQmlJS::Dom::DomUniverse::loadFile(), QQmlJS::Dom::DomEnvironment::loadFile(), QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(), QHstsHeaderParser::parse(), QCUPSSupport::parseJobHoldUntil(), QNetworkCookiePrivate::parseSetCookieHeaderLine(), QLockFile::tryLock(), QQmlJS::Dom::updateEntry(), and QTlsPrivate::X509CertificateOpenSSL::verify().
|
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.
Referenced by QSvgTinyDocument::currentElapsed(), QSvgTinyDocument::draw(), QSvgTinyDocument::draw(), QGeoPositionInfoSourceAndroid::processPositionUpdate(), QSvgTinyDocument::restartAnimation(), QDBusPlatformMenu::showPopup(), QGeoPositionInfoSourceAndroid::startUpdates(), and QQuickCanvasItem::updatePolish().
|
staticnoexcept |
Returns the number of seconds since the start, in UTC, of the year 1970.
This number is like the POSIX time_t variable.
Referenced by QQuickMouseArea::itemChange(), and qEncodeNtlmv2Response().
QDate QDateTime::date | ( | ) | const |
Returns the date part of the datetime.
Definition at line 3617 of file qdatetime.cpp.
References getMSecs(), getStatus(), msecsToDate(), and QDateTimePrivate::ValidDate.
Referenced by QOCIDateTime::QOCIDateTime(), QDateTimeParser::absoluteMax(), dateFromString(), QV4::DateObject::dateTimeToDate(), QCalendarBackend::dateTimeToString(), daysTo(), QDB2Result::exec(), QODBCResult::exec(), QQmlJS::Dom::DomUniverse::execQueue(), QDB2Driver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QODBCDriver::formatValue(), QDateTimeParser::fromString(), msecsTo(), QNmeaRealTimeReader::notifyNewUpdate(), QNmeaPositionInfoSourcePrivate::notifyNewUpdate(), operator<<(), QDateTimeParser::parse(), qOraOutValue(), QNmeaRealTimeReader::readAvailableData(), setDate(), QDateTimeEdit::setDateTime(), QDateTimeEdit::setMaximumDateTime(), QDateTimeEdit::setMinimumDateTime(), setTime(), ToDateString(), toEarliest(), toFileTime(), toLatest(), QV4::Date::toQDate(), QSystemLocalePrivate::toString(), toTimeStamp(), and writeMSDosDate().
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 4443 of file qdatetime.cpp.
References date(), QDate::daysTo(), and other().
Referenced by QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(), and QDateTimeParser::parse().
Definition at line 5091 of file qdatetime.cpp.
References fromMSecsSinceEpoch(), and QTimeZone::LocalTime.
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 5078 of file qdatetime.cpp.
References QTimeZone::isValid(), reviseTimeZone(), and setMSecsSinceEpoch().
Referenced by convertToExtendedType(), QDateTimeEditPrivate::dateTimeValue(), QQmlJS::Dom::DomUniverse::execQueue(), QDateTimeEdit::fixup(), fromMSecsSinceEpoch(), QResource::lastModified(), DocumentFile::lastModified(), operator>>(), AndroidPositioning::positionInfoFromJavaLocation(), QDateTimeEditPrivate::stepBy(), QQmlJS::Dom::ParsingTask::toCbor(), ToDateTime(), QTimeZonePrivate::toOffsetData(), and toTimeZone().
Definition at line 5123 of file qdatetime.cpp.
References fromSecsSinceEpoch(), and QTimeZone::LocalTime.
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 5110 of file qdatetime.cpp.
References QTimeZone::isValid(), reviseTimeZone(), and setSecsSinceEpoch().
Referenced by fromSecsSinceEpoch(), and QNetworkCookiePrivate::parseSetCookieHeaderLine().
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 3786 of file qdatetime.cpp.
References QDateTimePrivate::DaylightTime, QDateTimePrivate::ZoneState::dst, extractDaylightStatus(), getMSecs(), getSpec(), getStatus(), isValid(), QDateTimePrivate::localStateAtMillis(), Qt::LocalTime, Qt::OffsetFromUTC, Q_ASSERT, Qt::TimeZone, toMSecsSinceEpoch(), QDateTimePrivate::UnknownDaylightTime, and Qt::UTC.
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 3586 of file qdatetime.cpp.
References getStatus(), and QDateTimePrivate::ValidityMask.
Referenced by addDays(), addMonths(), addYears(), and QDateTimeEditPrivate::validateAndInterpret().
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 3606 of file qdatetime.cpp.
References getStatus(), and QDateTimePrivate::ValidDateTime.
Referenced by QDateTimeEdit::QDateTimeEdit(), QOCIDateTime::QOCIDateTime(), QDateTimeParser::absoluteMax(), addMSecs(), QmlLsp::QQmlCodeModel::buildPathsForFileUrl(), convertToExtendedType(), dateFromString(), dateTimeFromString(), QV4::DateObject::dateTimeToString(), QCalendarBackend::dateTimeToString(), QDateTimeEditPrivate::dateTimeValue(), QDate::endOfDay(), QNetworkDiskCache::expire(), QDB2Driver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QODBCDriver::formatValue(), QPSQLDriver::formatValue(), QSqlDriver::formatValue(), QNetworkHeadersPrivate::fromHttpDate(), QDateTimeParser::fromString(), isDaylightTime(), QHstsPolicy::isExpired(), QNetworkCookie::isSessionCookie(), QGeoPositionInfo::isValid(), QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(), msecsTo(), offsetFromUtc(), QTlsPrivate::X509CertificateGeneric::parse(), QDateTimeParser::parse(), parseDateString(), parseHttpDate(), QNetworkCookiePrivate::parseSetCookieHeaderLine(), ParseString(), QGeoAreaMonitorPolling::requestUpdate(), QDateTimeEdit::setDate(), QDateTimeEdit::setDateTime(), QFileSystemEngine::setFileTime(), QDateTimeEdit::setMaximumDateTime(), QDateTimeEdit::setMinimumDateTime(), QGeoAreaMonitorPolling::startMonitoring(), QDate::startOfDay(), timeFromString(), timeZoneAbbreviation(), toEarliest(), toLatest(), QLocale::toString(), QLocale::toString(), toTimeZone(), QDateTimeEditPrivate::validateAndInterpret(), QV4::ExecutableCompilationUnit::verifyHeader(), RCCFileInfo::writeDataInfo(), and writeMSDosDate().
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 4484 of file qdatetime.cpp.
References isValid(), other(), and toMSecsSinceEpoch().
Referenced by QQmlJS::Dom::DomEnvironment::finishLoadingDependencies(), QLockFilePrivate::isApparentlyStale(), msecsTo(), QDirSortItemComparator::operator()(), and secsTo().
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 3712 of file qdatetime.cpp.
References getMSecs(), getSpec(), isValid(), Qt::LocalTime, QtPrivate::DateTimeConstants::MSECS_PER_SEC, Q_ASSERT, toMSecsSinceEpoch(), and Qt::UTC.
Referenced by QCalendarBackend::dateTimeToString().
|
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 498 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 509 of file qdatetime.h.
Copies the other datetime into this and returns this copy.
Definition at line 3566 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 4465 of file qdatetime.cpp.
References QtPrivate::DateTimeConstants::MSECS_PER_SEC, msecsTo(), and other().
Referenced by QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed().
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.
Definition at line 3823 of file qdatetime.cpp.
References checkValidDateTime(), date(), setDateTime(), and time().
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 4000 of file qdatetime.cpp.
References QDateTimePrivate::DaylightTime, QDateTimePrivate::expressUtcAsLocal(), extractSpec(), getStatus(), QTimeZonePrivate::invalidSeconds(), QTimeZone::isUtcOrFixedOffset(), Qt::LocalTime, mergeDaylightStatus(), QtPrivate::DateTimeConstants::MSECS_PER_SEC, msecsCanBeSmall(), Qt::OffsetFromUTC, Q_ASSERT, Q_LIKELY, Q_UNLIKELY, qAddOverflow(), QtPrivate::DateTimeConstants::SECS_PER_DAY, specCanBeSmall(), QDateTimePrivate::StandardTime, state, Qt::TimeZone, QDateTimePrivate::ValidDateTime, and QDateTimePrivate::ValidityMask.
Referenced by addMSecs(), fromMSecsSinceEpoch(), and setSecsSinceEpoch().
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 4062 of file qdatetime.cpp.
References qMulOverflow(), setMSecsSinceEpoch(), and QDateTimePrivate::ValidityMask.
Referenced by fromSecsSinceEpoch().
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:
Definition at line 3842 of file qdatetime.cpp.
References checkValidDateTime(), date(), setDateTime(), and time().
Referenced by jobHoldToString(), operator-(), and QCUPSSupport::parseJobHoldUntil().
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()}.
Definition at line 3909 of file qdatetime.cpp.
References reviseTimeZone().
Referenced by QNetworkHeadersPrivate::fromHttpDate().
Swaps this datetime with other. This operation is very fast and never fails.
Definition at line 326 of file qdatetime.h.
QTime QDateTime::time | ( | ) | const |
Returns the time part of the datetime.
Definition at line 3628 of file qdatetime.cpp.
References getMSecs(), getStatus(), msecsToTime(), and QDateTimePrivate::ValidTime.
Referenced by QOCIDateTime::QOCIDateTime(), QCalendarBackend::dateTimeToString(), dateTimeToTime(), QDB2Result::exec(), QMimerSQLResult::exec(), QODBCResult::exec(), QDB2Driver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QODBCDriver::formatValue(), QDateTimeParser::fromString(), jobHoldToString(), msecsTo(), QNmeaRealTimeReader::notifyNewUpdate(), QNmeaPositionInfoSourcePrivate::notifyNewUpdate(), operator-(), operator<<(), QDateTimeParser::parse(), QCUPSSupport::parseJobHoldUntil(), processSentence(), qOraOutValue(), QNmeaRealTimeReader::readAvailableData(), setDate(), setTime(), timeFromString(), toEarliest(), toFileTime(), toLatest(), QV4::Date::toQTime(), QSystemLocalePrivate::toString(), toTimeStamp(), ToTimeString(), and writeMSDosDate().
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 3663 of file qdatetime.cpp.
Referenced by QDateTimeEdit::setDateTime(), and toTimeZone().
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 3644 of file qdatetime.cpp.
References getSpec().
Referenced by macValue(), operator<<(), and QDateTimeParser::skipToNextSection().
QString QDateTime::timeZoneAbbreviation | ( | ) | const |
Returns the Time Zone Abbreviation for this datetime.
The returned string depends on timeSpec():
\list
Definition at line 3751 of file qdatetime.cpp.
References extractDaylightStatus(), getMSecs(), getSpec(), getStatus(), Qt::ISODate, isValid(), QDateTimePrivate::localNameAtMillis(), Qt::LocalTime, Qt::OffsetFromUTC, Q_ASSERT, Qt::TimeZone, toOffsetString(), and Qt::UTC.
Referenced by QCalendarBackend::dateTimeToString().
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 4617 of file qdatetime.cpp.
References QTimeZone::LocalTime, and toTimeZone().
Referenced by dateTimeToTime(), operator<<(), and QCUPSSupport::parseJobHoldUntil().
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 3929 of file qdatetime.cpp.
References extractDaylightStatus(), getMSecs(), getSpec(), getStatus(), QDateTimePrivate::localStateAtMillis(), Qt::LocalTime, QtPrivate::DateTimeConstants::MSECS_PER_SEC, Qt::OffsetFromUTC, Q_ASSERT, state, Qt::TimeZone, and Qt::UTC.
Referenced by addMSecs(), currentTime(), QV4::DateObject::dateTimeToString(), QDateTimeEditPrivate::dateTimeValue(), QNetworkDiskCache::expire(), isDaylightTime(), msecsTo(), offsetFromUtc(), ParseString(), QFileSystemEngine::setFileTime(), toSecsSinceEpoch(), toTimeZone(), QV4::ExecutableCompilationUnit::verifyHeader(), and RCCFileInfo::writeDataInfo().
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 4601 of file qdatetime.cpp.
References QTimeZone::fromSecondsAheadOfUtc(), and toTimeZone().
Referenced by QCalendarBackend::dateTimeToString().
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 3980 of file qdatetime.cpp.
References QtPrivate::DateTimeConstants::MSECS_PER_SEC, and toMSecsSinceEpoch().
Referenced by QPixmap::load(), and QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed().
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 4656 of file qdatetime.cpp.
References fromMSecsSinceEpoch(), isValid(), ret, timeRepresentation(), and toMSecsSinceEpoch().
Referenced by QDateTimeEditPrivate::convertTimeZone(), QFileInfo::fileTime(), QDateTimeEdit::setDateTimeRange(), QDateTimeEdit::setMaximumDateTime(), QDateTimeEdit::setMinimumDateTime(), QDateTimeEditPrivate::stepBy(), ToDateTime(), toLocalTime(), toOffsetFromUtc(), toUTC(), QDateTimeEditPrivate::updateTimeZone(), and QDateTimeEditPrivate::validateAndInterpret().
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 4633 of file qdatetime.cpp.
References toTimeZone(), and QTimeZone::UTC.
Referenced by QCtfLibImpl::QCtfLibImpl(), QV4::DateObject::dateTimeToDate(), QPSQLDriver::formatValue(), jobHoldToString(), operator<<(), QNetworkCookie::operator==(), QNetworkHeadersPrivate::toHttpDate(), and QNetworkCookie::toRawForm().
Returns true
if lhs is different from rhs; otherwise returns false
.
Two datetimes are different if either the date, the time, or the time zone components are different. Since 5.14, all invalid datetime are equal (and less than all valid datetimes).
Definition at line 527 of file qdatetime.h.
|
friend |
Definition at line 488 of file qdatetime.h.
|
friend |
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 493 of file qdatetime.h.
|
friend |
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 504 of file qdatetime.h.
|
friend |
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 483 of file qdatetime.h.
Returns true
if lhs is earlier than rhs; otherwise returns false
.
Definition at line 528 of file qdatetime.h.
|
friend |
Writes dateTime to the out stream.
Definition at line 5489 of file qdatetime.cpp.
|
related |
Writes dateTime to the out stream.
Definition at line 5489 of file qdatetime.cpp.
Returns true
if lhs is earlier than or equal to rhs; otherwise returns false
.
Definition at line 529 of file qdatetime.h.
Returns true
if lhs is the same as rhs; otherwise returns false
.
Two datetimes are different if either the date, the time, or the time zone components are different. Since 5.14, all invalid datetime are equal (and less than all valid datetimes).
Definition at line 526 of file qdatetime.h.
Returns true
if lhs is later than rhs; otherwise returns false
.
Definition at line 530 of file qdatetime.h.
Returns true
if lhs is later than or equal to rhs; otherwise returns false
.
Definition at line 531 of file qdatetime.h.
|
friend |
Reads a datetime from the stream in into dateTime.
Definition at line 5554 of file qdatetime.cpp.
|
related |
Reads a datetime from the stream in into dateTime.
Definition at line 5554 of file qdatetime.cpp.
|
friend |
Definition at line 522 of file qdatetime.h.