CopperSpice API  1.9.0
QDateTime Class Reference

Stores date and time information. More...

Public Methods

 QDateTime ()
 
 QDateTime (const QDate &date)
 
 QDateTime (const QDate &date, const QTime &time, std::optional< QTimeZone > timeZone=std::nullopt)
 
 QDateTime (const QDateTime &other)
 
 QDateTime (QDateTime &&other)
 
 ~QDateTime ()
 
QDateTime addDays (qint64 days) const
 
QDateTime addDuration (std::chrono::milliseconds msecs) const
 
QDateTime addMonths (qint64 months) const
 
QDateTime addMSecs (qint64 msecs) const
 
QDateTime addSecs (qint64 seconds) const
 
QDateTime addYears (qint64 years) const
 
QDate date () const
 
qint64 daysTo (const QDateTime &value) const
 
bool isDaylightTime () const
 
bool isNull () const
 
bool isValid () const
 
qint64 msecsTo (const QDateTime &value) const
 
int offsetFromUtc () const
 
bool operator!= (const QDateTime &value) const
 
bool operator< (const QDateTime &value) const
 
bool operator<= (const QDateTime &value) const
 
QDateTime & operator= (const QDateTime &other)
 
QDateTime & operator= (QDateTime &&other)
 
bool operator== (const QDateTime &value) const
 
bool operator> (const QDateTime &value) const
 
bool operator>= (const QDateTime &value) const
 
qint64 secsTo (const QDateTime &value) const
 
void setDate (const QDate &date)
 
void setMSecsSinceEpoch (qint64 msecs)
 
void setSecsSinceEpoch (qint64 seconds)
 
void setTime (const QTime &time)
 
void setTime_t (quint64 seconds)
 
void setTimeZone (const QTimeZone &toZone)
 
void swap (QDateTime &other)
 
QTime time () const
 
QTimeZone timeRepresentation () const
 
QTimeZone timeZone () const
 
QString timeZoneAbbreviation () const
 
CFDateRef toCFDate () const
 
QDateTime toLocalTime () const
 
qint64 toMSecsSinceEpoch () const
 
NSDate * toNSDate () const
 
QDateTime toOffsetFromUtc (qint64 offsetSeconds) const
 
qint64 toSecsSinceEpoch () const
 
std::chrono::time_point< std::chrono::system_clock, std::chrono::milliseconds > toStdSysMilliseconds () const
 
std::chrono::time_point< std::chrono::system_clock, std::chrono::seconds > toStdSysSeconds () const
 
QString toString (const QString &format) const
 
QString toString (Qt::DateFormat format=Qt::TextDate) const
 
quint64 toTime_t () const
 
QDateTime toTimeZone (const QTimeZone &timeZone) const
 
QDateTime toUTC () const
 

Static Public Methods

static QDateTime currentDateTime (const QTimeZone &zone=QDate::default_tz ())
 
static QDateTime currentDateTimeUtc ()
 
static qint64 currentMSecsSinceEpoch ()
 
static qint64 currentSecsSinceEpoch ()
 
static QDateTime fromCFDate (CFDateRef date)
 
static QDateTime fromMSecsSinceEpoch (qint64 msecs, const QTimeZone &timeZone=QDate::default_tz ())
 
static QDateTime fromNSDate (const NSDate *date)
 
static QDateTime fromSecsSinceEpoch (qint64 seconds, const QTimeZone &timeZone=QDate::default_tz ())
 
static QDateTime fromStdLocalTime (const std::chrono::local_time< std::chrono::milliseconds > &msecs)
 
static QDateTime fromString (const QString &str, const QString &format)
 
static QDateTime fromString (const QString &str, Qt::DateFormat format=Qt::TextDate)
 
static QDateTime fromTime_t (qint64 seconds, const QTimeZone &timeZone=QDate::default_tz ())
 

Friends

QDataStreamoperator<< (QDataStream &stream, const QDateTime &dateTime)
 
QDataStreamoperator>> (QDataStream &stream, QDateTime &dateTime)
 

Detailed Description

The QDateTime class stores date and time information. The Julian calendar is used for any date prior to October 15 1582. The Gregorian calendar is used for dates after 15 October 1582. This class retrieves the current date and time from the operating system internal clock. Many of the methods in this class are used to calculate a new date or time based on a given offset or to compare two existing dates or times.

QDateTime does not account for leap seconds.

A QDateTime is typically created by specifying a QDate and a QTime or using the static method currentDateTime() which returns a new QDateTime based on the system clock. The date() and time() methods return a QDate and QTime. Calling toString() returns the date and time in a text format.

The date and time for a given QDateTime can be modified by calling setDate() and setTime(). The fromString() method returns a new QDateTime based on a quoted string and a date/time format.

There are a full set of operators to compare two QDateTime values where a smaller date/time one means earlier and a larger date/time is later.

Gregorian and Julian Calendars

The switch from the Julian calendar to the Gregorian calendar happened between October 4 1582 to October 15 1582. This 10 day gap is part of Roman history and the actually skipped these days to adjust to the new calendar. Other regions of the world made the calendar transition at different times, although many areas moved within a year. Notable exceptions are the British Empire which changed over in 1752 and Greece with moved to the Gregorian calendar in 1923.

CopperSpice follows the common practice of using the calendar corresponding to the Roman locale. QDateTime uses the Julian calendar for dates prior to October 4 1582 and the Gregorian calendar starting on October 15 1582. All dates within the gap are invalid.

If you use QDateTime for a calendar date in this range, the day after 4 October 1582 will be 15 October 1582.

Year 0

There is no year 0 and attempting to construct a date for that year results in an invalid QDateTime.

The year -1 refers to the year "1 before Christ" or BCE which stands for "before common era". The day before January 1 0001 is December 31 0001 BCE. The notation CE stands for "common era" and refers to dates "after Christ".

Before Common Era

  • lifetime of Alexander the Great
  • construction of the Egyptian Pyramids
  • abacus invented in Sumer and Babylonia

Common Era

  • development of computer software
  • invention of the moterized vehicles
  • birthday of anyone reading this documentation

Range of Valid Dates

The QDate class is implemented using a qint64 which stores the number of days since November 24 4714 BCE in the Gregorian calendar. QDateTime is also implemented using a qint64 which stores the number of milliseconds since Jan 1 1970 at midnight UTC.

For most use cases QDate and QDateTime will store the same date value. You should use QDate to prevent an overflow when the calendar date might be extremely far in the past or the future.

Use of System Timezone

QDateTime uses the operating system time zone information to determine the offset of local time from UTC. If the system is not configured correctly QDateTime may return incorrect values.

QDateTime::currentDateTime() returns a QDateTime expressed as local time. Use the method toUTC() to convert local time to UTC time. Operations such as addSecs() and secsTo() are aware of daylight saving time (DST).

Daylight Saving Time (DST)

QDateTime uses the operating system time zone database to determine when Daylight Saving Time starts and ends for a given locale.

See also
QDate, QDateTimeEdit, QTime, QTimeZone

Constructor & Destructor Documentation

QDateTime::QDateTime ( )

Constructs an invalid QDateTime.

See also
isValid()
QDateTime::QDateTime ( const QDate date)
explicit

Constructs a QDateTime with the given date and a valid QTime of 00:00:00.000.

QDateTime::QDateTime ( const QDate date,
const QTime time,
std::optional< QTimeZone timeZone = std::nullopt 
)

Constructs a new QDateTime with the given date and time using the specified timeZone. If the date is valid and time is not valid, the time will automatically be set to midnight. If the specified timeZone is invalid the QDateTime will be invalid.

QDateTime::QDateTime ( const QDateTime &  other)

Copy constructs a new QDateTime from other.

QDateTime::QDateTime ( QDateTime &&  other)

Move constructs a new QDateTime from other.

QDateTime::~QDateTime ( )

Destroys this QDateTime.

Method Documentation

QDateTime QDateTime::addDays ( qint64  days) const
nodiscard

Adds the number of days to the current QDateTime and returns the result. If days is negative the value for days is subtracted from this QDateTime.

See also
addMonths(), addYears(), addSecs(), daysTo()
QDateTime QDateTime::addDuration ( std::chrono::milliseconds  msecs) const

Adds the number of msecs to the current QDateTime and returns the result. If msecs is negative the value for msecs is subtracted from this QDateTime.

See also
addMSecs(), msecsTo()
QDateTime QDateTime::addMonths ( qint64  months) const
nodiscard

Adds the given number of months to the current QDateTime and returns the result. If months is negative the value for months is subtracted from this QDateTime.

See also
addDays(), addSecs(), addYears(), daysTo()
QDateTime QDateTime::addMSecs ( qint64  msecs) const
nodiscard

Adds the number of msecs to the current QDateTime and returns the result. If msecs is negative the value for msecs is subtracted from this QDateTime.

See also
addSecs(), msecsTo()
QDateTime QDateTime::addSecs ( qint64  seconds) const
nodiscard

Adds the given number of seconds to the current QDateTime and returns the result. If seconds is negative the value for seconds is subtracted from this QDateTime.

See also
addDays(), addMonths(), addMSecs(), addYears(), secsTo()
QDateTime QDateTime::addYears ( qint64  years) const
nodiscard

Adds the given number of years to the current QDateTime and returns the result. If years is negative the value for years is subtracted from this QDateTime.

See also
addDays(), addMonths(), addSecs(), daysTo()
QDateTime QDateTime::currentDateTime ( const QTimeZone zone = QDate::default_tz())
static

Returns the current QDateTime based on the system clock. If no value for zone is passed the local time zone will be used.

See also
currentDateTimeUtc(), QDate::currentDate(), QTime::currentTime()
QDateTime QDateTime::currentDateTimeUtc ( )
static

Returns a QDateTime based on the system clock, in UTC.

See also
currentDateTime(), QDate::currentDate(), QTime::currentTime()
qint64 QDateTime::currentMSecsSinceEpoch ( )
static

Returns the number of milliseconds since Jan 1 1970 at midnight UTC.

See also
currentDateTime(), currentDateTimeUtc(), toTime_t()
qint64 QDateTime::currentSecsSinceEpoch ( )
static

Returns the number of seconds since Jan 1 1970 at midnight UTC.

See also
currentDateTime(), currentDateTimeUtc(), toTime_t()
QDate QDateTime::date ( ) const

Returns the date part of the current QDateTime.

See also
setDate(), time()
qint64 QDateTime::daysTo ( const QDateTime &  value) const

Returns the number of days between the current QDateTime and the given value. If the new QDateTime is earlier than the original QDateTime, the value returned is negative.

See also
addDays(), secsTo(), msecsTo()
QDateTime QDateTime::fromCFDate ( CFDateRef  date)
static

Constructs a new QDateTime containing a copy of the CFDate date.

Note
This method is only available on Mac OS X.
See also
toCFDate()
QDateTime QDateTime::fromMSecsSinceEpoch ( qint64  msecs,
const QTimeZone timeZone = QDate::default_tz() 
)
static

Returns a QDateTime where the date and time correspond to the given number of msecs since Jan 1 1970 at midnight UTC, with the specified timeZone.

See also
fromTime_t()
QDateTime QDateTime::fromNSDate ( const NSDate *  date)
static

Constructs a new QDateTime containing a copy of the NSDate date.

Note
This method is only available on Mac OS X.
See also
toNSDate()
QDateTime QDateTime::fromSecsSinceEpoch ( qint64  seconds,
const QTimeZone timeZone = QDate::default_tz() 
)
static

Returns a QDateTime containing the date and time equal to the number of seconds after Jan 1 1970 at midnight UTC. If a valid timeZone is specified the returned QDateTime will be adjusted accordingly. If no timeZone is passed the local system time zone will be used.

There are values for seconds which will result in a QDateTime that is invalid. For these values the behavior of this method is undefined.

See also
fromMSecsSinceEpoch(), setSecsSinceEpoch(), toSecsSinceEpoch()
QDateTime QDateTime::fromStdLocalTime ( const std::chrono::local_time< std::chrono::milliseconds > &  msecs)
inlinestatic

Returns a QDateTime where the date and time is calculated by adding msecs to Jan 1 1970 at midnight local time.

Note
This method is only available if your compiler supports the C++20 features of std::chrono.
QDateTime QDateTime::fromString ( const QString str,
const QString format 
)
static

Returns the QDateTime represented by str using the given format. Returns an invalid QDateTime if str does not match the specified format.

The day and month names must be given in the user locale. You can only use the English names if the current locale is English.

These expressions may be used for the date part of the format string.

ExpressionOutput
dthe day as number without a leading zero (1 to 31)
ddthe day as number with a leading zero (01 to 31)
dddthe abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName().
ddddthe long localized day name (e.g. 'Monday' to 'Sunday'). Uses QDate::longDayName().
Mthe month as number without a leading zero (1-12)
MMthe month as number with a leading zero (01-12)
MMMthe abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName().
MMMMthe long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName().
yythe year as two digit number (00-99)
yyyythe year as four digit number

These expressions may be used for the time part of the format string.

ExpressionOutput
hhour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hhhour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
Hhour without a leading zero (0 to 23, even with AM/PM display)
HHhour with a leading zero (00 to 23, even with AM/PM display)
mminute without a leading zero (0 to 59)
mmminute with a leading zero (00 to 59)
ssecond without a leading zero (0 to 59)
sssecond with a leading zero (00 to 59)
zmilliseconds without leading zeroes (0 to 999)
zzzmilliseconds with leading zeroes (000 to 999)
AP or Ainterpret as an AM/PM time, AP must be either "AM" or "PM".
ap or aInterpret as an AM/PM time, ap must be either "am" or "pm".

All other input characters will be treated as text. Any sequence of characters that are enclosed in singlequotes will also be treated as text and not be used as an expression.

QTime time1 = QTime::fromString("131", "HHh");
// time1 is 13:00:00
QTime time2 = QTime::fromString("1apA", "1amAM");
// time2 is 01:00:00
QDateTime dateTime = QDateTime::fromString("M1d1y9800:01:02", "'M'M'd'd'y'yyhh:mm:ss");
// dateTime is 1 January 1998 00:01:02

If the format is not satisfied an invalid QDateTime is returned.

The expressions which do not expect leading zeroes (d, M) will be greedy. This means they will use two digits even if this will put them outside the accepted range of values and leaves too few digits for other sections. For example, the following format string does not mean January 30 because the M will grab two digits, resulting in an invalid date.

QDateTime dateTime = QDateTime::fromString("130", "Mm"); // invalid

For any field that is not represented in the format the following defaults are used:

FieldDefault value
Year1900
Month1 (January)
Day1
Hour0
Minute0
Second0
QDateTime dateTime = QDateTime::fromString("1.30.1", "M.d.s"); // dateTime is January 30 in 1900 at 00:00:01.
See also
QDate::fromString(), QTime::fromString(), QDate::toString()
QDateTime QDateTime::fromString ( const QString str,
Qt::DateFormat  format = Qt::TextDate 
)
static

Returns the QDateTime represented by str using the given format. Returns an invalid QDateTime if str does not match the specified format.

QDateTime QDateTime::fromTime_t ( qint64  seconds,
const QTimeZone timeZone = QDate::default_tz() 
)
static

Returns a QDateTime where the date and time are the number of seconds since Jan 1 1970 at midnight UTC with the given timeZone.

See also
toTime_t(), setTime_t()
bool QDateTime::isDaylightTime ( ) const

Returns true if this QDateTime falls in the region of Daylight Saving Time.

bool QDateTime::isNull ( ) const

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

See also
QDate::isNull(), QTime::isNull(), isValid()
bool QDateTime::isValid ( ) const

Returns true if both the date and the time are valid, otherwise returns false.

See also
QDate::isValid(), QTime::isValid()
qint64 QDateTime::msecsTo ( const QDateTime &  value) const

Returns the number of milliseconds between the current QDateTime and the given value. If the new QDateTime is earlier than the original QDateTime, the value returned is negative.

This method will convert both QDateTime values to UTC. This will ensure the result is correct if one of the values uses daylight saving time (DST) and the other does not.

See also
addMSecs(), daysTo(), QTime::msecsTo()
int QDateTime::offsetFromUtc ( ) const

Returns the number of seconds between the time zone for this QDateTime and the UTC clock.

bool QDateTime::operator!= ( const QDateTime &  value) const
inline

Returns true if this QDateTime is different from the given value, otherwise returns false. Two datetimes are different if the date, the time, or the time zone components are different.

See also
operator==()
bool QDateTime::operator< ( const QDateTime &  value) const

Returns true if this QDateTime is earlier than the given value, otherwise returns false.

bool QDateTime::operator<= ( const QDateTime &  value) const
inline

Returns true if this QDateTime is earlier than or equal to the given value, otherwise returns false.

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

Copy assigns from other and returns a reference to this object.

QDateTime & QDateTime::operator= ( QDateTime &&  other)
inline

Move assigns from other and returns a reference to this object.

bool QDateTime::operator== ( const QDateTime &  value) const

Returns true if this QDateTime is equal to the given value, otherwise returns false.

See also
operator!=()
bool QDateTime::operator> ( const QDateTime &  value) const
inline

Returns true if this QDateTime is later than the given value, otherwise returns false.

bool QDateTime::operator>= ( const QDateTime &  value) const
inline

Returns true if this QDateTime is later than or equal to the given value, otherwise returns false.

qint64 QDateTime::secsTo ( const QDateTime &  value) const

Returns the number of seconds between the current QDateTime and the given value. If the new QDateTime is earlier than the original QDateTime, the value returned is negative.

This method will convert both QDateTime values to UTC. This will ensure the result is correct if one of the values uses daylight saving time (DST) and the other does not.

QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
qDebug("There are %d seconds to Christmas", now.secsTo(xmas));
See also
addSecs(), daysTo(), QTime::secsTo()
void QDateTime::setDate ( const QDate date)

Sets the date part of this QDateTime to date. If no time is set, the time is set to midnight.

See also
date(), setTime()
void QDateTime::setMSecsSinceEpoch ( qint64  msecs)

Sets the date and time for this QDateTime which corresponds to the given number of msecs since Jan 1 1970 at midnight UTC.

There are values for msecs which will result in a QDateTime that is invalid. For these values the behavior of this method is undefined.

See also
toMSecsSinceEpoch(), setTime_t()
void QDateTime::setSecsSinceEpoch ( qint64  seconds)

Sets the date and time for this QDateTime which corresponds to the given number of seconds since Jan 1 1970 at midnight UTC.

See also
fromSecsSinceEpoch(), setMSecsSinceEpoch(), toSecsSinceEpoch()
void QDateTime::setTime ( const QTime time)

Sets the time part of this QDateTime to time.

See also
time(), setDate()
void QDateTime::setTime_t ( quint64  seconds)

Sets the date and time which correspond to the given number of seconds since Jan 1 1970 at midnight UTC.

See also
toTime_t()
void QDateTime::setTimeZone ( const QTimeZone toZone)

Sets the time zone for this QDateTime to toZone. If the specified time zone is invalid then the QDateTime will be invalid.

See also
timeZone()
void QDateTime::swap ( QDateTime &  other)
inline

Swaps other with this QDateTime.

QTime QDateTime::time ( ) const

Returns the time part of this QDateTime.

See also
setTime(), date()
QTimeZone QDateTime::timeRepresentation ( ) const

Returns the time zone for the current QDateTime. Equivalent to calling QDateTime::timeZone().

See also
setTimeZone()
QTimeZone QDateTime::timeZone ( ) const

Returns the time zone for the current QDateTime. Equivalent to calling QDateTime::timeRepresentation().

See also
setTimeZone()
QString QDateTime::timeZoneAbbreviation ( ) const

Returns the Time Zone Abbreviation for this QDateTime. The abbreviation is not guaranteed to be unique to a particular time zone and should not be used in place of the ID or display name.

An example abbreviation for Chicago or New Orleans would be CST or CDT for "central standard time" and "central daylight time". In Amsterdam or Berlin the abbreviation will be CET or CEST for "central european time" and "central european summer time".

See also
QTimeZone::abbreviation()
CFDateRef QDateTime::toCFDate ( ) const

Creates a CFDate from this QDateTime. The caller owns the CFDate object and is responsible for releasing it.

Note
This method is only available on Mac OS X.
See also
fromCFDate()
QDateTime QDateTime::toLocalTime ( ) const

Returns the current QDateTime converted to the local time zone.

qint64 QDateTime::toMSecsSinceEpoch ( ) const

Returns this QDateTime as the number of milliseconds since Jan 1 1970 at midnight UTC. This method returns a unique value for all valid dates. If the QDateTime is invalid the result is undefined.

See also
toTime_t(), setMSecsSinceEpoch()
NSDate * QDateTime::toNSDate ( ) const

Creates an NSDate from a QDateTime. The NSDate object is autoreleased.

Note
This method is only available on Mac OS X.
See also
fromNSDate()
QDateTime QDateTime::toOffsetFromUtc ( qint64  offsetSeconds) const

Returns a copy of the current QDateTime which is converted to a time zone corresponding to the offsetSeconds relative to UTC. If the offsetSeconds equals 0 then the date time will be in UTC.

See also
offsetFromUtc()
qint64 QDateTime::toSecsSinceEpoch ( ) const

Converts this QDateTime to the number of seconds since Jan 1 1970 at midnight UTC. For all valid dates this method returns a unique value.

On systems which do not support time zones this method will behave as if local time were UTC. The behavior for this method is undefined if the QDateTime is not valid.

See also
toMSecsSinceEpoch(), fromSecsSinceEpoch(), setSecsSinceEpoch()
std::chrono::time_point< std::chrono::system_clock, std::chrono::milliseconds > QDateTime::toStdSysMilliseconds ( ) const
inline

Converts this QDateTime to a value in milliseconds using the std::chrono::system_clock. The value is the duration from Jan 1 1970 at midnight UTC to this QDateTime.

See also
fromStdLocalTime(), toMSecsSinceEpoch()
std::chrono::time_point< std::chrono::system_clock, std::chrono::seconds > QDateTime::toStdSysSeconds ( ) const
inline

Converts this QDateTime to a value in seconds using the std::chrono::system_clock. The value is the duration from Jan 1 1970 at midnight UTC to this QDateTime.

See also
fromStdLocalTime(), toSecsSinceEpoch()
QString QDateTime::toString ( const QString format) const

Returns this QDateTime as a string. The format parameter determines the format of the result string. If the QDateTime is invalid an empty string will be returned.

These expressions are used for the date.

ExpressionOutput
dthe day as number without a leading zero (1 to 31)
ddthe day as number with a leading zero (01 to 31)
dddthe abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName().
ddddthe long localized day name (e.g. 'Monday' to 'Sunday'). Uses QDate::longDayName().
Mthe month as number without a leading zero (1-12)
MMthe month as number with a leading zero (01-12)
MMMthe abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName().
MMMMthe long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName().
yythe year as two digit number (00-99)
yyyythe year as four digit number

These expressions are used for the time.

ExpressionOutput
hhour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hhhour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
mminute without a leading zero (0 to 59)
mmminute with a leading zero (00 to 59)
ssecond without a leading zero (0 to 59)
sssecond with a leading zero (00 to 59)
zmilliseconds without leading zeroes (0 to 999)
zzzmilliseconds with leading zeroes (000 to 999)
APAM/PM display. AP will be replaced by either "AM" or "PM".
apam/pm display. ap will be replaced by either "am" or "pm".

All other input characters will be ignored. Any sequence of characters which are enclosed in single quotes will be treated as text and not used as an expression. Two consecutive singlequotes are replaced by a single quote in the output.

The following examples assume the QDateTime is "21 May 2001 14:13:09".

FormatResult
dd.MM.yyyy21.05.2001
ddd MMMM d yyTue May 21 01
hh:mm:ss.zzz14:13:09.042
h:m:s ap2:13:9 pm
See also
QDate::toString(), QTime::toString()
QString QDateTime::toString ( Qt::DateFormat  format = Qt::TextDate) const

Returns this QDateTime as a string in the given format. If this QDateTime is invalid an empty string will be returned.

  • Qt::TextDate formats the string using the default as specified in the Qt::DateFormat enum. An example of this formatting is "Tue May 20 03:40:13 2008".
  • Qt::ISODate uses the ISO 8601 extended specification of yyyy-MM-ddThh:mm:ss[Z|[+|-]hh:mm]. This format is only valid for years in the range 0 to 9999.
  • Qt::RFC2822Date uses the specification d MMM yyyy hh:mm:ss [+|-]hh:mm.
  • Qt::SystemLocaleShortDate or Qt::SystemLocaleLongDate will format the string based on the locale settings of the current system.
  • Qt::DefaultLocaleShortDate or Qt::DefaultLocaleLongDate formats the string depends on the default application locale. The default locale is set by calling QLocale::setDefault(). If no default locale has been set the system locale will be used.
See also
fromString(), Qt::DateFormat
quint64 QDateTime::toTime_t ( ) const

Converts this QDateTime to the number of seconds which have elapsed since Jan 1, 1970 at midnight UTC.

See also
toMSecsSinceEpoch(), setTime_t()
QDateTime QDateTime::toTimeZone ( const QTimeZone timeZone) const

Returns a copy of this QDateTime converted to the given timeZone.

See also
timeZone()
QDateTime QDateTime::toUTC ( ) const

Converts the current QDateTime to UTC.

Refer to UTC Defined for additional information.

Friends And Related Function Documentation

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

Writes the given dateTime to the stream. Returns a reference to the stream.

Refer to Serializing Data Types for additional information.

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

Reads from the stream into the given dateTime. Returns a reference to the stream.

Refer to Serializing Data Types for additional information.