QtBase  v6.3.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
QDateTime Class Reference

The QDateTime class provides date and time functions. More...

#include <qdatetime.h>

Public Types

enum class  YearRange : qint32 { First = -292275056 , Last = +292278994 }
 

Public Member Functions

 QDateTime () noexcept
 
 QDateTime (QDate date, QTime time, Qt::TimeSpec spec=Qt::LocalTime, int offsetSeconds=0)
 
 QDateTime (const QDateTime &other) noexcept
 
 QDateTime (QDateTime &&other) noexcept
 
 ~QDateTime ()
 
QDateTimeoperator= (const QDateTime &other) noexcept
 
void swap (QDateTime &other) noexcept
 
bool isNull () const
 
bool isValid () const
 
QDate date () const
 
QTime time () const
 
Qt::TimeSpec timeSpec () const
 
int offsetFromUtc () const
 
QString timeZoneAbbreviation () const
 
bool isDaylightTime () const
 
qint64 toMSecsSinceEpoch () const
 
qint64 toSecsSinceEpoch () const
 
void setDate (QDate date)
 
void setTime (QTime time)
 
void setTimeSpec (Qt::TimeSpec spec)
 
void setOffsetFromUtc (int offsetSeconds)
 
void setMSecsSinceEpoch (qint64 msecs)
 
void setSecsSinceEpoch (qint64 secs)
 
QDateTime addDays (qint64 days) const
 
QDateTime addMonths (int months) const
 
QDateTime addYears (int years) const
 
QDateTime addSecs (qint64 secs) const
 
QDateTime addMSecs (qint64 msecs) const
 
QDateTime toTimeSpec (Qt::TimeSpec spec) const
 
QDateTime toLocalTime () const
 
QDateTime toUTC () const
 
QDateTime toOffsetFromUtc (int offsetSeconds) const
 
qint64 daysTo (const QDateTime &) const
 
qint64 secsTo (const QDateTime &) const
 
qint64 msecsTo (const QDateTime &) const
 

Static Public Member Functions

static QDateTime currentDateTime ()
 
static QDateTime currentDateTimeUtc ()
 
static QDateTime fromMSecsSinceEpoch (qint64 msecs, Qt::TimeSpec spec=Qt::LocalTime, int offsetFromUtc=0)
 
static QDateTime fromSecsSinceEpoch (qint64 secs, Qt::TimeSpec spec=Qt::LocalTime, int offsetFromUtc=0)
 
static qint64 currentMSecsSinceEpoch () noexcept
 
static qint64 currentSecsSinceEpoch () noexcept
 

Friends

class QDateTimePrivate
 
bool operator== (const QDateTime &lhs, const QDateTime &rhs)
 
bool operator!= (const QDateTime &lhs, const QDateTime &rhs)
 
bool operator< (const QDateTime &lhs, const QDateTime &rhs)
 
bool operator<= (const QDateTime &lhs, const QDateTime &rhs)
 
bool operator> (const QDateTime &lhs, const QDateTime &rhs)
 
bool operator>= (const QDateTime &lhs, const QDateTime &rhs)
 
Q_CORE_EXPORT QDataStreamoperator<< (QDataStream &, const QDateTime &)
 
Q_CORE_EXPORT QDataStreamoperator>> (QDataStream &, QDateTime &)
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &out, const QDateTime &dateTime)
 
QDataStreamoperator>> (QDataStream &in, QDateTime &dateTime)
 

Detailed Description

The QDateTime class provides date and time functions.

\inmodule QtCore

\reentrant

A QDateTime object encodes a calendar date and a clock time (a "datetime"). 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}, in conjunction with the QTimeZone class. For example, a time zone of "Europe/Berlin" will apply the daylight-saving rules as used in Germany. In contrast, an 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 offset or changes. When using either local time or a specified time zone, time-zone transitions such as the starts and ends of daylight-saving time (DST; but see below) are taken into account. The choice of system used to represent a datetime is described as its "timespec".

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 00:00:00 on January 1, 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 time with respect to local time. QDateTime::currentDateTimeUtc() returns a QDateTime that expresses the current time with respect to 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 toTimeSpec() to express a datetime in local time or UTC, toOffsetFromUtc() to express in terms of an offset from UTC, or toTimeZone() to express it with respect to a general time zone. You can use timeSpec() to find out what time-spec a QDateTime object stores its time relative to. When that is Qt::TimeZone, you can use timeZone() to find out which zone it is using.

Note
QDateTime does not account for leap seconds.

Definition at line 237 of file qdatetime.h.

Member Enumeration Documentation

◆ YearRange

Since
5.14

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.

Note
QDate can describe dates in a wider range of years. For most purposes, this makes little difference, as the range of years that QDateTime can support reaches 292 million years either side of 1970.
See also
isValid(), QDate
Enumerator
First 
Last 

Definition at line 390 of file qdatetime.h.

Constructor & Destructor Documentation

◆ QDateTime() [1/4]

QDateTime::QDateTime ( )
noexcept

Constructs a null datetime.

A null datetime is invalid, since its date and time are invalid.

See also
isValid()

Definition at line 3623 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ QDateTime() [2/4]

QDateTime::QDateTime ( QDate  date,
QTime  time,
Qt::TimeSpec  spec = Qt::LocalTime,
int  offsetSeconds = 0 
)

Constructs a datetime with the given date and time, using the time specification defined by spec and offsetSeconds seconds.

If date is valid and time is not, the time will be set to midnight.

If the spec is not Qt::OffsetFromUTC then offsetSeconds will be ignored.

If the spec is Qt::OffsetFromUTC and offsetSeconds is 0 then the timeSpec() will be set to Qt::UTC, i.e. an offset of 0 seconds.

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

Definition at line 3648 of file qdatetime.cpp.

◆ QDateTime() [3/4]

QDateTime::QDateTime ( const QDateTime other)
noexcept

Constructs a copy of the other datetime.

Definition at line 3674 of file qdatetime.cpp.

◆ QDateTime() [4/4]

QDateTime::QDateTime ( QDateTime &&  other)
noexcept
Since
5.8 Moves the content of the temporary other datetime to this object and leaves other in an unspecified (but proper) state.

Definition at line 3684 of file qdatetime.cpp.

◆ ~QDateTime()

QDateTime::~QDateTime ( )

Destroys the datetime.

Definition at line 3692 of file qdatetime.cpp.

Member Function Documentation

◆ addDays()

QDateTime QDateTime::addDays ( qint64  ndays) const

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.

See also
daysTo(), addMonths(), addYears(), addSecs()

Definition at line 4425 of file qdatetime.cpp.

Here is the call graph for this function:

◆ addMonths()

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.

See also
daysTo(), addDays(), addYears(), addSecs()

Definition at line 4450 of file qdatetime.cpp.

Here is the call graph for this function:

◆ addMSecs()

QDateTime 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).

If this datetime is invalid, an invalid datetime will be returned.

See also
addSecs(), msecsTo(), addDays(), addMonths(), addYears()

Definition at line 4513 of file qdatetime.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addSecs()

QDateTime QDateTime::addSecs ( qint64  s) const

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.

See also
addMSecs(), secsTo(), addDays(), addMonths(), addYears()

Definition at line 4496 of file qdatetime.cpp.

Here is the call graph for this function:

◆ addYears()

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.

See also
daysTo(), addDays(), addMonths(), addSecs()

Definition at line 4475 of file qdatetime.cpp.

Here is the call graph for this function:

◆ currentDateTime()

QDateTime QDateTime::currentDateTime ( )
static

Returns the current datetime, as reported by the system clock, in the local time zone.

See also
currentDateTimeUtc(), QDate::currentDate(), QTime::currentTime(), toTimeSpec()
Here is the caller graph for this function:

◆ currentDateTimeUtc()

QDateTime QDateTime::currentDateTimeUtc ( )
static
Since
4.7 Returns the current datetime, as reported by the system clock, in UTC.
See also
currentDateTime(), QDate::currentDate(), QTime::currentTime(), toTimeSpec()
Here is the caller graph for this function:

◆ currentMSecsSinceEpoch()

qint64 QDateTime::currentMSecsSinceEpoch ( )
staticnoexcept
Since
4.7

Returns the number of milliseconds since 1970-01-01T00:00:00 Universal Coordinated Time. This number is like the POSIX time_t variable, but expressed in milliseconds instead.

See also
currentDateTime(), currentDateTimeUtc(), toTimeSpec()
Here is the caller graph for this function:

◆ currentSecsSinceEpoch()

qint64 QDateTime::currentSecsSinceEpoch ( )
staticnoexcept
Since
5.8

Returns the number of seconds since 1970-01-01T00:00:00 Universal Coordinated Time.

See also
currentMSecsSinceEpoch()

◆ date()

QDate QDateTime::date ( ) const

Returns the date part of the datetime.

See also
setDate(), time(), timeSpec()

Definition at line 3753 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ daysTo()

qint64 QDateTime::daysTo ( const QDateTime other) const

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:

See also
addDays(), secsTo(), msecsTo()

Definition at line 4575 of file qdatetime.cpp.

Here is the call graph for this function:

◆ fromMSecsSinceEpoch()

QDateTime QDateTime::fromMSecsSinceEpoch ( qint64  msecs,
Qt::TimeSpec  spec = Qt::LocalTime,
int  offsetSeconds = 0 
)
static

Returns a datetime whose date and time are the number of milliseconds msecs that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC) and converted to the given spec.

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.

If the spec is not Qt::OffsetFromUTC then the offsetSeconds will be ignored. If the spec is Qt::OffsetFromUTC and the offsetSeconds is 0 then the spec will be set to Qt::UTC, i.e. an offset of 0 seconds.

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

See also
toMSecsSinceEpoch(), setMSecsSinceEpoch()

Definition at line 4968 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ fromSecsSinceEpoch()

QDateTime QDateTime::fromSecsSinceEpoch ( qint64  secs,
Qt::TimeSpec  spec = Qt::LocalTime,
int  offsetSeconds = 0 
)
static
Since
5.8

Returns a datetime whose date and time are the number of seconds secs that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC) and converted to the given spec.

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.

If the spec is not Qt::OffsetFromUTC then the offsetSeconds will be ignored. If the spec is Qt::OffsetFromUTC and the offsetSeconds is 0 then the spec will be set to Qt::UTC, i.e. an offset of 0 seconds.

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

See also
toSecsSinceEpoch(), setSecsSinceEpoch()

Definition at line 4996 of file qdatetime.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isDaylightTime()

bool QDateTime::isDaylightTime ( ) const
Since
5.2

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.

See also
timeSpec()

Definition at line 3920 of file qdatetime.cpp.

Here is the call graph for this function:

◆ isNull()

bool QDateTime::isNull ( ) const

Returns true if both the date and the time are null; otherwise returns false. A null datetime is invalid.

See also
QDate::isNull(), QTime::isNull(), isValid()

Definition at line 3721 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ isValid()

bool QDateTime::isValid ( ) const

Returns true if both the date and the time are valid and they are valid in the current Qt::TimeSpec, otherwise returns false.

If the timeSpec() is Qt::LocalTime or Qt::TimeZone and this object represents a time that was skipped by a forward transition, then it is invalid. For example, if DST ends at 2am with the clock advancing to 3am, then date-times from 02:00:00 to 02:59:59.999 on that day are considered invalid.

See also
QDateTime::YearRange, QDate::isValid(), QTime::isValid()

Definition at line 3741 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ msecsTo()

qint64 QDateTime::msecsTo ( const QDateTime other) const

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.

See also
addMSecs(), daysTo(), QTime::msecsTo()

Definition at line 4616 of file qdatetime.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ offsetFromUtc()

int QDateTime::offsetFromUtc ( ) const
Since
5.2

Returns this date-time's Offset From UTC in seconds.

The result depends on timeSpec(): \list

For 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).

See also
setOffsetFromUtc()

Definition at line 3843 of file qdatetime.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

QDateTime & QDateTime::operator= ( const QDateTime other)
noexcept

Makes a copy of the other datetime and returns a reference to the copy.

Definition at line 3701 of file qdatetime.cpp.

Here is the call graph for this function:

◆ secsTo()

qint64 QDateTime::secsTo ( const QDateTime other) const

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:

See also
addSecs(), daysTo(), QTime::secsTo()

Definition at line 4597 of file qdatetime.cpp.

Here is the call graph for this function:

◆ setDate()

void QDateTime::setDate ( QDate  date)

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.

See also
date(), setTime(), setTimeSpec()

Definition at line 3953 of file qdatetime.cpp.

◆ setMSecsSinceEpoch()

void QDateTime::setMSecsSinceEpoch ( qint64  msecs)
Since
4.7

Sets the date and time given the number of milliseconds msecs that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC). 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.

See also
toMSecsSinceEpoch(), setSecsSinceEpoch()

Definition at line 4132 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ setOffsetFromUtc()

void QDateTime::setOffsetFromUtc ( int  offsetSeconds)
Since
5.2

Sets the timeSpec() to Qt::OffsetFromUTC and the offset to offsetSeconds. The datetime will refer to a different point in time.

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

If offsetSeconds is 0 then the timeSpec() will be set to Qt::UTC.

See also
isValid(), offsetFromUtc()

Definition at line 4018 of file qdatetime.cpp.

◆ setSecsSinceEpoch()

void QDateTime::setSecsSinceEpoch ( qint64  secs)
Since
5.8

Sets the date and time given the number of seconds secs that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC). On systems that do not support time zones this function will behave as if local time were Qt::UTC.

See also
toSecsSinceEpoch(), setMSecsSinceEpoch()

Definition at line 4202 of file qdatetime.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTime()

void QDateTime::setTime ( QTime  time)

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:

dt.setTime(QTime());
The QDateTime class provides date and time functions.
Definition: qdatetime.h:238
static QDateTime currentDateTime()
void setTime(QTime time)
Definition: qdatetime.cpp:3972
The QTime class provides clock time functions.
Definition: qdatetime.h:166
See also
time(), setDate(), setTimeSpec()

Definition at line 3972 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ setTimeSpec()

void QDateTime::setTimeSpec ( Qt::TimeSpec  spec)

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

If spec is Qt::OffsetFromUTC then the timeSpec() will be set to Qt::UTC, i.e. an effective offset of 0.

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

Example:

See also
timeSpec(), setDate(), setTime(), setTimeZone(), Qt::TimeSpec

Definition at line 3994 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ swap()

void QDateTime::swap ( QDateTime other)
inlinenoexcept
Since
5.0

Swaps this datetime with other. This operation is very fast and never fails.

Definition at line 296 of file qdatetime.h.

Here is the call graph for this function:

◆ time()

QTime QDateTime::time ( ) const

Returns the time part of the datetime.

See also
setTime(), date(), timeSpec()

Definition at line 3769 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ timeSpec()

Qt::TimeSpec QDateTime::timeSpec ( ) const

Returns the time specification of the datetime.

See also
setTimeSpec(), date(), time(), Qt::TimeSpec

Definition at line 3785 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ timeZoneAbbreviation()

QString QDateTime::timeZoneAbbreviation ( ) const
Since
5.2

Returns the Time Zone Abbreviation for this datetime.

The returned string depends on timeSpec():

\list

Note
The abbreviation is not guaranteed to be unique, i.e. different time zones may have the same abbreviation. For Qt::LocalTime and Qt::TimeZone, when returned by the host system, the abbreviation may be localized.
See also
timeSpec(), QTimeZone::abbreviation()

Definition at line 3882 of file qdatetime.cpp.

Here is the call graph for this function:

◆ toLocalTime()

QDateTime QDateTime::toLocalTime ( ) const
inline

Returns a datetime containing the date and time information in this datetime, but specified using the Qt::LocalTime definition.

Example:

See also
toTimeSpec()

Definition at line 339 of file qdatetime.h.

Here is the caller graph for this function:

◆ toMSecsSinceEpoch()

qint64 QDateTime::toMSecsSinceEpoch ( ) const
Since
4.7

Returns the datetime as the number of milliseconds that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC).

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.

See also
toSecsSinceEpoch(), setMSecsSinceEpoch()

Definition at line 4061 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ toOffsetFromUtc()

QDateTime QDateTime::toOffsetFromUtc ( int  offsetSeconds) const
Since
5.2

Returns a copy of this datetime converted to a spec of Qt::OffsetFromUTC with the given offsetSeconds.

If the offsetSeconds equals 0 then a UTC datetime will be returned

See also
setOffsetFromUtc(), offsetFromUtc(), toTimeSpec()

Definition at line 4667 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ toSecsSinceEpoch()

qint64 QDateTime::toSecsSinceEpoch ( ) const
Since
5.8

Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC).

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.

See also
toMSecsSinceEpoch(), setSecsSinceEpoch()

Definition at line 4113 of file qdatetime.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toTimeSpec()

QDateTime QDateTime::toTimeSpec ( Qt::TimeSpec  spec) const

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

If spec is Qt::OffsetFromUTC then it is set to Qt::UTC. To set to a spec of Qt::OffsetFromUTC use toOffsetFromUtc().

If spec is Qt::TimeZone then it is set to Qt::LocalTime, i.e. the local Time Zone.

Example:

See also
timeSpec(), toTimeZone(), toOffsetFromUtc()

Definition at line 4640 of file qdatetime.cpp.

Here is the caller graph for this function:

◆ toUTC()

QDateTime QDateTime::toUTC ( ) const
inline

Returns a datetime containing the date and time information in this datetime, but specified using the Qt::UTC definition.

Example:

See also
toTimeSpec()

Definition at line 340 of file qdatetime.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

bool QDateTime::operator!= ( const QDateTime lhs,
const QDateTime rhs 
)
friend

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).

See also
operator==()

Definition at line 400 of file qdatetime.h.

◆ operator<

bool QDateTime::operator< ( const QDateTime lhs,
const QDateTime rhs 
)
friend

Returns true if lhs is earlier than rhs; otherwise returns false.

See also
operator==()

Definition at line 401 of file qdatetime.h.

◆ operator<< [1/2]

QDataStream & operator<< ( QDataStream out,
const QDateTime dateTime 
)
friend

Writes dateTime to the out stream.

See also
{Serializing Qt Data Types}

Definition at line 5411 of file qdatetime.cpp.

◆ operator<<() [2/2]

QDataStream & operator<< ( QDataStream out,
const QDateTime dateTime 
)
related

Writes dateTime to the out stream.

See also
{Serializing Qt Data Types}

Definition at line 5411 of file qdatetime.cpp.

◆ operator<=

bool QDateTime::operator<= ( const QDateTime lhs,
const QDateTime rhs 
)
friend

Returns true if lhs is earlier than or equal to rhs; otherwise returns false.

See also
operator==()

Definition at line 402 of file qdatetime.h.

◆ operator==

bool QDateTime::operator== ( const QDateTime lhs,
const QDateTime rhs 
)
friend

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).

See also
operator!=(), operator<(), operator<=(), operator>(), operator>=()

Definition at line 399 of file qdatetime.h.

◆ operator>

bool QDateTime::operator> ( const QDateTime lhs,
const QDateTime rhs 
)
friend

Returns true if lhs is later than rhs; otherwise returns false.

See also
operator==()

Definition at line 403 of file qdatetime.h.

◆ operator>=

bool QDateTime::operator>= ( const QDateTime lhs,
const QDateTime rhs 
)
friend

Returns true if lhs is later than or equal to rhs; otherwise returns false.

See also
operator==()

Definition at line 404 of file qdatetime.h.

◆ operator>> [1/2]

QDataStream & operator>> ( QDataStream in,
QDateTime dateTime 
)
friend

Reads a datetime from the stream in into dateTime.

See also
{Serializing Qt Data Types}

Definition at line 5475 of file qdatetime.cpp.

◆ operator>>() [2/2]

QDataStream & operator>> ( QDataStream in,
QDateTime dateTime 
)
related

Reads a datetime from the stream in into dateTime.

See also
{Serializing Qt Data Types}

Definition at line 5475 of file qdatetime.cpp.

◆ QDateTimePrivate

friend class QDateTimePrivate
friend

Definition at line 395 of file qdatetime.h.


The documentation for this class was generated from the following files: