Qt 4.8
|
The QDateTime class provides date and time functions. More...
#include <qdatetime.h>
Public Functions | |
QDateTime | addDays (int days) const |
Returns a QDateTime object containing a datetime ndays days later than the datetime of this object (or earlier if ndays is negative). More... | |
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). More... | |
QDateTime | addMSecs (qint64 msecs) const |
Returns a QDateTime object containing a datetime msecs miliseconds later than the datetime of this object (or earlier if msecs is negative). More... | |
QDateTime | addSecs (int secs) const |
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or earlier if s is negative). More... | |
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). More... | |
QDate | date () const |
Returns the date part of the datetime. More... | |
int | daysTo (const QDateTime &) const |
Returns the number of days from this datetime to the other datetime. More... | |
bool | isNull () const |
Returns true if both the date and the time are null; otherwise returns false. More... | |
bool | isValid () const |
Returns true if both the date and the time are valid; otherwise returns false. More... | |
qint64 | msecsTo (const QDateTime &) const |
Returns the number of milliseconds from this datetime to the other datetime. More... | |
bool | operator!= (const QDateTime &other) const |
Returns true if this datetime is different from the other datetime; otherwise returns false. More... | |
bool | operator< (const QDateTime &other) const |
Returns true if this datetime is earlier than the other datetime; otherwise returns false. More... | |
bool | operator<= (const QDateTime &other) const |
Returns true if this datetime is earlier than or equal to the other datetime; otherwise returns false. More... | |
QDateTime & | operator= (const QDateTime &other) |
Makes a copy of the other datetime and returns a reference to the copy. More... | |
bool | operator== (const QDateTime &other) const |
Returns true if this datetime is equal to the other datetime; otherwise returns false. More... | |
bool | operator> (const QDateTime &other) const |
Returns true if this datetime is later than the other datetime; otherwise returns false. More... | |
bool | operator>= (const QDateTime &other) const |
Returns true if this datetime is later than or equal to the other datetime; otherwise returns false. More... | |
QDateTime () | |
Constructs a null datetime (i.e. More... | |
QDateTime (const QDate &) | |
Constructs a datetime with the given date, a valid time(00:00:00.000), and sets the timeSpec() to Qt::LocalTime. More... | |
QDateTime (const QDate &, const QTime &, Qt::TimeSpec spec=Qt::LocalTime) | |
Constructs a datetime with the given date and time, using the time specification defined by spec. More... | |
QDateTime (const QDateTime &other) | |
Constructs a copy of the other datetime. More... | |
int | secsTo (const QDateTime &) const |
Returns the number of seconds from this datetime to the other datetime. More... | |
void | setDate (const QDate &date) |
Sets the date part of this datetime to date. More... | |
void | setMSecsSinceEpoch (qint64 msecs) |
Sets the date and time given the number of milliseconds,msecs, that have passed since 1970-01-01T00:00:00. More... | |
void | setTime (const QTime &time) |
Sets the time part of this datetime to time. More... | |
void | setTime_t (uint secsSince1Jan1970UTC) |
Sets the date and time given the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC). More... | |
void | setTimeSpec (Qt::TimeSpec spec) |
Sets the time specification used in this datetime to spec. More... | |
void | setUtcOffset (int seconds) |
QTime | time () const |
Returns the time part of the datetime. More... | |
Qt::TimeSpec | timeSpec () const |
Returns the time specification of the datetime. More... | |
QDateTime | toLocalTime () const |
Returns a datetime containing the date and time information in this datetime, but specified using the Qt::LocalTime definition. More... | |
qint64 | toMSecsSinceEpoch () const |
Returns the datetime as the number of milliseconds that have passed since 1970-01-01T00:00:00. More... | |
QString | toString (Qt::DateFormat f=Qt::TextDate) const |
Returns the datetime as a string in the format given. More... | |
QString | toString (const QString &format) const |
Returns the datetime as a string. More... | |
uint | toTime_t () const |
Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC). More... | |
QDateTime | toTimeSpec (Qt::TimeSpec spec) const |
Returns a copy of this datetime configured to use the given time specification. More... | |
QDateTime | toUTC () const |
Returns a datetime containing the date and time information in this datetime, but specified using the Qt::UTC definition. More... | |
int | utcOffset () const |
~QDateTime () | |
Destroys the datetime. More... | |
Static Public Functions | |
static QDateTime | currentDateTime () |
Returns the current datetime, as reported by the system clock, in the local time zone. More... | |
static QDateTime | currentDateTimeUtc () |
Returns the current datetime, as reported by the system clock, in UTC. More... | |
static qint64 | currentMSecsSinceEpoch () |
Returns the number of milliseconds since 1970-01-01T00:00:00 Universal Coordinated Time. More... | |
static QDateTime | fromMSecsSinceEpoch (qint64 msecs) |
Returns a datetime whose date and time are the number of milliseconds, msecs, that have passed since 1970-01-01T00:00:00. More... | |
static QDateTime | fromString (const QString &s, Qt::DateFormat f=Qt::TextDate) |
Returns the QDateTime represented by the string, using the format given, or an invalid datetime if this is not possible. More... | |
static QDateTime | fromString (const QString &s, const QString &format) |
Returns the QDateTime represented by the string, using the format given, or an invalid datetime if the string cannot be parsed. More... | |
static QDateTime | fromTime_t (uint secsSince1Jan1970UTC) |
Returns a datetime whose date and time are the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC). More... | |
Private Functions | |
void | detach () |
Properties | |
QExplicitlySharedDataPointer< QDateTimePrivate > | d |
Friends | |
Q_CORE_EXPORT QDataStream & | operator<< (QDataStream &, const QDateTime &) |
Writes dateTime to the out stream. More... | |
Q_CORE_EXPORT QDataStream & | operator>> (QDataStream &, QDateTime &) |
Reads a datetime from the stream in into dateTime. More... | |
class | QDateTimePrivate |
The QDateTime class provides date and time functions.
A QDateTime object contains a calendar date and a clock time (a "datetime"). It is a combination 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.
A QDateTime object is typically created either by giving a date and time explicitly in the constructor, or by using the static function currentDateTime() that returns a QDateTime object set to the system clock's time. The date and time can be changed with setDate() and setTime(). A datetime can also be set using the setTime_t() function that takes a POSIX-standard "number of seconds since 00:00:00 on January 1, 1970" value. The fromString() function returns a QDateTime, given a string and a date format used to interpret the date within the string.
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.
QDateTime can store datetimes as local time or as UTC. QDateTime::currentDateTime() returns a QDateTime expressed as local time; use toUTC() to convert it to UTC. You can also use timeSpec() to find out if a QDateTime object stores a UTC time or a local time. Operations such as addSecs() and secsTo() are aware of daylight saving time (DST).
Definition at line 216 of file qdatetime.h.
QDateTime::QDateTime | ( | ) |
Constructs a null datetime (i.e.
null date and null time). A null datetime is invalid, since the date is invalid.
Definition at line 2267 of file qdatetime.cpp.
Referenced by addDays(), addMonths(), QDateTimePrivate::addMSecs(), addYears(), currentDateTime(), currentDateTimeUtc(), currentMSecsSinceEpoch(), fromString(), QDateTimeParser::getMaximum(), QDateTimeParser::getMinimum(), localToUtc(), QDateTimeParser::parse(), and QDateTimeParser::setDigit().
|
explicit |
Constructs a datetime with the given date, a valid time(00:00:00.000), and sets the timeSpec() to Qt::LocalTime.
Definition at line 2278 of file qdatetime.cpp.
QDateTime::QDateTime | ( | const QDate & | date, |
const QTime & | time, | ||
Qt::TimeSpec | spec = Qt::LocalTime |
||
) |
Constructs a datetime with the given date and time, using the time specification defined by spec.
If date is valid and time is not, the time will be set to midnight.
Definition at line 2292 of file qdatetime.cpp.
QDateTime::QDateTime | ( | const QDateTime & | other | ) |
QDateTime::~QDateTime | ( | ) |
QDateTime QDateTime::addDays | ( | int | ndays | ) | const |
Returns a QDateTime object containing a datetime ndays days later than the datetime of this object (or earlier if ndays is negative).
Definition at line 2783 of file qdatetime.cpp.
Referenced by QPatternist::AbstractDurationComparator::addDurationToDateTime(), operator+(), operator-(), and QDateTimeEditPrivate::stepBy().
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).
Definition at line 2796 of file qdatetime.cpp.
Referenced by QPatternist::AbstractDurationComparator::addDurationToDateTime(), and QDateTimeParser::parse().
Returns a QDateTime object containing a datetime msecs miliseconds later than the datetime of this object (or earlier if msecs is negative).
Definition at line 2881 of file qdatetime.cpp.
Referenced by QPatternist::AbstractDurationComparator::addDurationToDateTime(), QDateTimePrivate::addMSecs(), QDateTimePrivate::getUTC(), and localToUtc().
QDateTime QDateTime::addSecs | ( | int | s | ) | const |
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or earlier if s is negative).
Definition at line 2869 of file qdatetime.cpp.
Referenced by QPatternist::AbstractDurationComparator::addDurationToDateTime(), QNetworkAccessHttpBackend::fetchCacheMetaData(), QNetworkAccessCache::linkEntry(), QNetworkAccessHttpBackend::loadFromCacheIfAllowed(), operator-(), QDateTimeParser::parse(), parseDateString(), QNetworkCookiePrivate::parseSetCookieHeaderLine(), q_getTimeFromASN1(), and qtValue().
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).
Definition at line 2809 of file qdatetime.cpp.
Referenced by QPatternist::AbstractDurationComparator::addDurationToDateTime().
|
static |
Returns the current datetime, as reported by the system clock, in the local time zone.
Use the currentDateTime() overload that takes no parameters instead.
Definition at line 3138 of file qdatetime.cpp.
Referenced by _q_fixupDateTime(), QZipWriterPrivate::addEntry(), QTransportAuth::authFromMessage(), QNetworkCookieJar::cookiesForUrl(), QUuid::createUuid(), currentMSecsSinceEpoch(), DumpIDL(), QPSPrintEnginePrivate::emitHeader(), QNetworkAccessHttpBackend::fetchCacheMetaData(), QNetworkSessionManagerPrivate::forceSessionClose(), QScriptDebuggerLocalsModelPrivate::get(), QSslCertificate::isValid(), QNetworkAccessCache::linkEntry(), QNetworkAccessHttpBackend::loadFromCacheIfAllowed(), QScriptErrorLogWidget::message(), QNetworkCookiePrivate::parseSetCookieHeaderLine(), QScriptScriptData::QScriptScriptData(), qt_CoCreateGuid(), qt_x11_apply_settings_in_all_apps(), QNetworkCookieJar::setCookiesFromUrl(), QConnmanEngine::startTime(), QNetworkSessionPrivateImpl::stateChange(), QNetworkAccessCache::timerEvent(), QNetworkAccessCache::updateTimer(), and QPdfEnginePrivate::writeInfo().
|
static |
Returns the current datetime, as reported by the system clock, in UTC.
Definition at line 3150 of file qdatetime.cpp.
Referenced by currentMSecsSinceEpoch().
|
static |
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.
Definition at line 3162 of file qdatetime.cpp.
Referenced by QElapsedTimer::elapsed(), and QElapsedTimer::restart().
QDate QDateTime::date | ( | ) | const |
Returns the date part of the datetime.
Definition at line 2357 of file qdatetime.cpp.
Referenced by _q_fixupDateTime(), _q_parseDosDir(), _q_parseUnixDir(), QDateTimeParser::absoluteMax(), adjustDate(), QScript::DateTimeToMs(), QStyledItemDelegate::displayText(), QDB2Result::exec(), QODBCResult::exec(), QPatternist::YearFromAbstractDateTimeFN::extract(), QPatternist::DayFromAbstractDateTimeFN::extract(), QPatternist::MonthFromAbstractDateTimeFN::extract(), QDeclarativeEnginePrivate::formatDate(), QDB2Driver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QODBCDriver::formatValue(), QPSQLDriver::formatValue(), QPatternist::GMonthDay::fromDateTime(), QPatternist::Date::fromDateTime(), QPatternist::GDay::fromDateTime(), QPatternist::GMonth::fromDateTime(), QPatternist::GYear::fromDateTime(), QPatternist::GYearMonth::fromDateTime(), QDateTimeParser::fromString(), fromString(), QDeclarativeCompiler::genLiteralAssignment(), QDateTimeParser::getDigit(), QDateTimePrivate::getLocal(), QDateTimePrivate::getUTC(), localToUtc(), operator*(), operator<<(), QDateTimeParser::parse(), QDateTimeParser::parseSection(), QDateTimeParser::potentialValue(), QDateTime(), QDateTimeToDATE(), qMakeOraDate(), setDate(), QDateTimeEdit::setDateTime(), QDateTimeParser::setDigit(), QDateTimeEdit::setMaximumDateTime(), QDateTimeEdit::setMinimumDateTime(), QDateTimeEditPrivate::stepBy(), QPatternist::AtomicValue::toQt(), QSystemLocalePrivate::toString(), QLocale::toString(), toTimeStamp(), QItemDelegatePrivate::valueToText(), QPdfEnginePrivate::writeInfo(), and writeMSDosDate().
int QDateTime::daysTo | ( | const QDateTime & | other | ) | const |
Returns the number of days from this datetime to the other datetime.
If the other datetime is earlier than this datetime, the value returned is negative.
Definition at line 2894 of file qdatetime.cpp.
Referenced by QNetworkAccessHttpBackend::loadFromCacheIfAllowed(), operator-(), and QDateTimeParser::parse().
|
private |
Definition at line 3791 of file qdatetime.cpp.
Referenced by setDate(), setMSecsSinceEpoch(), setTime(), setTime_t(), setTimeSpec(), and setUtcOffset().
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). On systems that do not support time zones, the time will be set as if local time were Qt::UTC.
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 3393 of file qdatetime.cpp.
Referenced by operator==().
|
static |
Returns the QDateTime represented by the string, using the format given, or an invalid datetime if this is not possible.
Note for Qt::TextDate: It is recommended that you use the English short month names (e.g. "Jan"). Although localized month names can also be used, they depend on the user's locale settings.
Definition at line 3487 of file qdatetime.cpp.
Referenced by convert(), QPSQLResult::data(), QDeclarativeStringConverters::dateTimeFromString(), QNetworkHeadersPrivate::fromHttpDate(), QNetworkAccessFtpBackend::ftpRawCommandReply(), and qDateTimeFromString().
Returns the QDateTime represented by the string, using the format given, or an invalid datetime if the string cannot be parsed.
These expressions may be used for the date part of the format string:
Expression | Output |
d | the day as number without a leading zero (1 to 31) |
dd | the day as number with a leading zero (01 to 31) |
ddd | the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName(). |
dddd | the long localized day name (e.g. 'Monday' to 'Sunday'). Uses QDate::longDayName(). |
M | the month as number without a leading zero (1-12) |
MM | the month as number with a leading zero (01-12) |
MMM | the abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName(). |
MMMM | the long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName(). |
yy | the year as two digit number (00-99) |
yyyy | the year as four digit number |
These expressions may be used for the time part of the format string:
Expression | Output |
h | the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) |
hh | the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) |
H | the hour without a leading zero (0 to 23, even with AM/PM display) |
HH | the hour with a leading zero (00 to 23, even with AM/PM display) |
m | the minute without a leading zero (0 to 59) |
mm | the minute with a leading zero (00 to 59) |
s | the second without a leading zero (0 to 59) |
ss | the second with a leading zero (00 to 59) |
z | the milliseconds without leading zeroes (0 to 999) |
zzz | the milliseconds with leading zeroes (000 to 999) |
AP or A | interpret as an AM/PM time. AP must be either "AM" or "PM". |
ap or a | Interpret 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.
If the format is not satisfied an invalid QDateTime is returned. The expressions that don't have leading zeroes (d, M, h, m, s, z) will be greedy. This means that they will use two digits even if this will put them outside the range and/or leave too few digits for other sections.
This could have meant 1 January 00:30.00 but the M will grab two digits.
For any field that is not represented in the format the following defaults are used:
Field | Default value |
Year | 1900 |
Month | 1 (January) |
Day | 1 |
Hour | 0 |
Minute | 0 |
Second | 0 |
For example:
Definition at line 3748 of file qdatetime.cpp.
Returns a datetime whose date and time are the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC).
On systems that do not support time zones, the time will be set as if local time were Qt::UTC.
Definition at line 3369 of file qdatetime.cpp.
Referenced by QFileSystemMetaData::fileTime().
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 2334 of file qdatetime.cpp.
Referenced by QDateTimeToDATE(), QConnmanEngine::startTime(), and QDateTimeEditPrivate::validateAndInterpret().
bool QDateTime::isValid | ( | ) | const |
Returns true if both the date and the time are valid; otherwise returns false.
Definition at line 2346 of file qdatetime.cpp.
Referenced by _q_parseUnixDir(), QDateTimeParser::absoluteMax(), QPatternist::AbstractDateTime::AbstractDateTime(), convert(), QPatternist::AdjustDateTimeToTimezoneFN::createValue(), QPatternist::AdjustDateToTimezoneFN::createValue(), QPatternist::AdjustTimeToTimezoneFN::createValue(), QDeclarativeStringConverters::dateTimeFromString(), QScript::DateTimeToMs(), QDB2Driver::formatValue(), QSqlDriver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QTDSDriver::formatValue(), QODBCDriver::formatValue(), QPSQLDriver::formatValue(), QPatternist::Date::fromDateTime(), QPatternist::SchemaTime::fromDateTime(), QPatternist::DateTime::fromDateTime(), QNetworkHeadersPrivate::fromHttpDate(), QPatternist::Date::fromValue(), QPatternist::SchemaTime::fromValue(), QPatternist::DateTime::fromValue(), QNetworkCookie::isSessionCookie(), QNetworkAccessHttpBackend::loadFromCacheIfAllowed(), QDateTimeParser::parse(), parseDateString(), parseHttpDate(), QNetworkCookiePrivate::parseSetCookieHeaderLine(), QDateTimeEdit::QDateTimeEdit(), QDateTimeToDATE(), QScriptScriptData::QScriptScriptData(), QDateTimeEdit::setDateTime(), QDateTimeEdit::setMaximumDateTime(), QDateTimeEdit::setMinimumDateTime(), QTest::toString(), toString(), QLocale::toString(), utcOffset(), 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 one of the two datetimes has daylight saving time (DST) and the other doesn't.
Definition at line 2942 of file qdatetime.cpp.
|
inline |
Returns true if this datetime is different from the other datetime; otherwise returns false.
Two datetimes are different if either the date, the time, or the time zone components are different.
Definition at line 257 of file qdatetime.h.
bool QDateTime::operator< | ( | const QDateTime & | other | ) | const |
Returns true if this datetime is earlier than the other datetime; otherwise returns false.
Definition at line 3025 of file qdatetime.cpp.
|
inline |
Returns true if this datetime is earlier than or equal to the other datetime; otherwise returns false.
Definition at line 259 of file qdatetime.h.
Makes a copy of the other datetime and returns a reference to the copy.
Definition at line 2321 of file qdatetime.cpp.
bool QDateTime::operator== | ( | const QDateTime & | other | ) | const |
Returns true if this datetime is equal to the other datetime; otherwise returns false.
Definition at line 2991 of file qdatetime.cpp.
|
inline |
Returns true if this datetime is later than the other datetime; otherwise returns false.
Definition at line 260 of file qdatetime.h.
|
inline |
Returns true if this datetime is later than or equal to the other datetime; otherwise returns false.
Definition at line 261 of file qdatetime.h.
int 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 one of the two datetimes has daylight saving time (DST) and the other doesn't.
Example:
Definition at line 2914 of file qdatetime.cpp.
Referenced by _q_fixupDateTime(), QNetworkAccessHttpBackend::loadFromCacheIfAllowed(), FAREnforcer::logAuthAttempt(), macValue(), QDirSortItemComparator::operator()(), operator-(), QConnmanEngine::startTime(), and QNetworkAccessCache::updateTimer().
void QDateTime::setDate | ( | const QDate & | date | ) |
Sets the date part of this datetime to date.
If no time is set, it is set to midnight.
Definition at line 2399 of file qdatetime.cpp.
Referenced by _q_fixupDateTime(), _q_parseDosDir(), _q_parseUnixDir(), fileTimeToQDateTime(), QPatternist::Date::fromDateTime(), and QPatternist::SchemaTime::fromDateTime().
void QDateTime::setMSecsSinceEpoch | ( | qint64 | msecs | ) |
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 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 2530 of file qdatetime.cpp.
Referenced by fromMSecsSinceEpoch().
void QDateTime::setTime | ( | const QTime & | time | ) |
Sets the time part of this datetime to time.
Definition at line 2416 of file qdatetime.cpp.
Referenced by fileTimeToQDateTime(), QPatternist::SchemaTime::fromDateTime(), operator+(), and operator-().
void QDateTime::setTime_t | ( | uint | seconds | ) |
Sets the date and time given the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC).
Use the single-argument overload of setTime_t() instead.
On systems that do not support time zones this function will behave as if local time were Qt::UTC.
Definition at line 2566 of file qdatetime.cpp.
Referenced by fileTimeToQDateTime(), fromTime_t(), QNetworkAccessHttpBackend::loadFromCacheIfAllowed(), macValue(), and qtValue().
void QDateTime::setTimeSpec | ( | Qt::TimeSpec | spec | ) |
Sets the time specification used in this datetime to spec.
Definition at line 2431 of file qdatetime.cpp.
Referenced by QPatternist::AbstractDateTime::copyTimeSpec(), QNetworkHeadersPrivate::fromHttpDate(), and QPatternist::AbstractDateTime::setUtcOffset().
void QDateTime::setUtcOffset | ( | int | seconds | ) |
Sets the offset from UTC to seconds, and also sets timeSpec() to Qt::OffsetFromUTC.
The maximum and minimum offset is 14 positive or negative hours. If seconds is larger or smaller than that, the result is undefined.
0 as offset is identical to UTC. Therefore, if seconds is 0, the timeSpec() will be set to Qt::UTC. Hence the UTC offset always relates to UTC, and can never relate to local time.
Definition at line 3416 of file qdatetime.cpp.
Referenced by QPatternist::AbstractDateTime::copyTimeSpec(), fromString(), and QPatternist::AbstractDateTime::setUtcOffset().
QTime QDateTime::time | ( | ) | const |
Returns the time part of the datetime.
Definition at line 2368 of file qdatetime.cpp.
Referenced by currentMSecsSinceEpoch(), QScript::DateTimeToMs(), QStyledItemDelegate::displayText(), QDB2Result::exec(), QODBCResult::exec(), QPatternist::HoursFromAbstractDateTimeFN::extract(), QPatternist::MinutesFromAbstractDateTimeFN::extract(), QPatternist::SecondsFromAbstractDateTimeFN::extract(), QDeclarativeEnginePrivate::formatTime(), QDB2Driver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QODBCDriver::formatValue(), QPSQLDriver::formatValue(), QPatternist::SchemaTime::fromDateTime(), QDateTimeParser::fromString(), fromString(), QDeclarativeCompiler::genLiteralAssignment(), QDateTimeParser::getDigit(), QDateTimePrivate::getLocal(), QDateTimePrivate::getUTC(), localToUtc(), operator*(), operator+(), operator-(), operator/(), operator<<(), operator==(), QDateTimeParser::parse(), QDateTime(), QDateTimeToDATE(), qMakeOraDate(), QDateTimeEdit::setDateTime(), QDateTimeParser::setDigit(), setTime(), QPatternist::AbstractDateTime::timeToString(), QSystemLocalePrivate::toString(), QLocale::toString(), toTimeStamp(), QItemDelegatePrivate::valueToText(), QPdfEnginePrivate::writeInfo(), and writeMSDosDate().
Qt::TimeSpec QDateTime::timeSpec | ( | ) | const |
Returns the time specification of the datetime.
Definition at line 2379 of file qdatetime.cpp.
Referenced by addDays(), addMonths(), QDateTimePrivate::addMSecs(), addYears(), QPatternist::AbstractDateTime::copyTimeSpec(), QPatternist::AbstractDateTimeComparator::equals(), QPatternist::TimezoneFromAbstractDateTimeFN::extract(), macValue(), operator<<(), QTest::toString(), and QPatternist::AbstractDateTime::zoneOffsetToString().
|
inline |
Returns a datetime containing the date and time information in this datetime, but specified using the Qt::LocalTime definition.
Definition at line 250 of file qdatetime.h.
Referenced by fromString(), and QScript::MsToDateTime().
qint64 QDateTime::toMSecsSinceEpoch | ( | ) | const |
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. \sa toTime_t(), setMSecsSinceEpoch()
Definition at line 2474 of file qdatetime.cpp.
Referenced by operator==(), and toTime_t().
QString QDateTime::toString | ( | Qt::DateFormat | format = Qt::TextDate | ) | const |
Returns the datetime as a string in the format given.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
If the format is Qt::TextDate, the string is formatted in the default way. QDate::shortDayName(), QDate::shortMonthName(), and QTime::toString() are used to generate the string, so the day and month names will be localized names. An example of this formatting is "Wed May 20 03:40:13 1998".
If the format is Qt::ISODate, the string format corresponds to the ISO 8601 extended specification for representations of dates and times, taking the form YYYY-MM-DDTHH:mm:ss[Z|[+|-]HH:mm], depending on the timeSpec() of the QDateTime. If the timeSpec() is Qt::UTC, Z will be appended to the string; if the timeSpec() is Qt::OffsetFromUTC the offset in hours and minutes from UTC will be appended to the string.
If the format is Qt::SystemLocaleShortDate or Qt::SystemLocaleLongDate, the string format depends on the locale settings of the system. Identical to calling QLocale::system().toString(datetime, QLocale::ShortFormat) or QLocale::system().toString(datetime, QLocale::LongFormat).
If the format is Qt::DefaultLocaleShortDate or Qt::DefaultLocaleLongDate, the string format depends on the default application locale. This is the locale set with QLocale::setDefault(), or the system locale if no default locale has been set. Identical to calling QLocale().toString(datetime, QLocale::ShortFormat) or QLocale().toString(datetime, QLocale::LongFormat).
If the datetime is invalid, an empty string will be returned.
Definition at line 2628 of file qdatetime.cpp.
Referenced by QPatternist::AbstractDateTime::dateToString(), DumpIDL(), QPSPrintEnginePrivate::emitHeader(), QDeclarativeEnginePrivate::formatDateTime(), QSqlDriver::formatValue(), QTDSDriver::formatValue(), fromScriptValue(), QScriptDebuggerLocalsModelPrivate::get(), QDateTimeParser::getDigit(), QLibraryPrivate::isPlugin(), operator<<(), QDateTimeParser::parse(), QDateTimeParser::setDigit(), QPatternist::GYear::stringValue(), QPatternist::GYearMonth::stringValue(), QPatternist::GMonth::stringValue(), QPatternist::GDay::stringValue(), QPatternist::GMonthDay::stringValue(), QPatternist::AbstractDateTime::timeToString(), and QTest::toString().
Returns the datetime as a string.
The format parameter determines the format of the result string.
These expressions may be used for the date:
Expression | Output |
d | the day as number without a leading zero (1 to 31) |
dd | the day as number with a leading zero (01 to 31) |
ddd | the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName(). |
dddd | the long localized day name (e.g. 'Monday' to 'Qt::Sunday'). Uses QDate::longDayName(). |
M | the month as number without a leading zero (1-12) |
MM | the month as number with a leading zero (01-12) |
MMM | the abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName(). |
MMMM | the long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName(). |
yy | the year as two digit number (00-99) |
yyyy | the year as four digit number |
These expressions may be used for the time:
Expression | Output |
h | the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) |
hh | the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) |
m | the minute without a leading zero (0 to 59) |
mm | the minute with a leading zero (00 to 59) |
s | the second without a leading zero (0 to 59) |
ss | the second with a leading zero (00 to 59) |
z | the milliseconds without leading zeroes (0 to 999) |
zzz | the milliseconds with leading zeroes (000 to 999) |
AP | use AM/PM display. AP will be replaced by either "AM" or "PM". |
ap | use am/pm display. ap will be replaced by either "am" or "pm". |
All other input characters will be ignored. Any sequence of characters that are enclosed in singlequotes will be treated as text and not be used as an expression. Two consecutive singlequotes ("''") are replaced by a singlequote in the output.
Example format strings (assumed that the QDateTime is 21 May 2001 14:13:09):
Format | Result |
dd.MM.yyyy | 21.05.2001 |
ddd MMMM d yy | Tue May 21 01 |
hh:mm:ss.zzz | 14:13:09.042 |
h:m:s ap | 2:13:9 pm |
If the datetime is invalid, an empty string will be returned.
Definition at line 2769 of file qdatetime.cpp.
uint QDateTime::toTime_t | ( | ) | const |
Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC).
On systems that do not support time zones, this function will behave as if local time were Qt::UTC.
If the date is outside the range 1970-01-01T00:00:00 to 2106-02-07T06:28:14, this function returns -1 cast to an unsigned integer (i.e., 0xFFFFFFFF).
To get an extended range, use toMSecsSinceEpoch().
Definition at line 2505 of file qdatetime.cpp.
Referenced by QNetworkSessionManagerPrivate::forceSessionClose(), QPixmap::load(), QNetworkAccessHttpBackend::loadFromCacheIfAllowed(), qEncodeNtlmv2Response(), and qt_CoCreateGuid().
QDateTime QDateTime::toTimeSpec | ( | Qt::TimeSpec | specification | ) | const |
Returns a copy of this datetime configured to use the given time specification.
Definition at line 2969 of file qdatetime.cpp.
Referenced by QDateTimeParser::parse(), QDateTimeEdit::setDateTimeRange(), QDateTimeEdit::setMaximumDateTime(), QDateTimeEdit::setMinimumDateTime(), QDateTimeEditPrivate::stepBy(), and QDateTimeEditPrivate::updateTimeSpec().
|
inline |
Returns a datetime containing the date and time information in this datetime, but specified using the Qt::UTC definition.
Definition at line 251 of file qdatetime.h.
Referenced by QScript::DateTimeToMs(), QNetworkAccessHttpBackend::loadFromCacheIfAllowed(), QNetworkCookie::operator==(), operator>=(), QNetworkCookiePrivate::parseSetCookieHeaderLine(), QPatternist::AtomicValue::toQt(), QNetworkCookie::toRawForm(), and QPdfEnginePrivate::writeInfo().
int QDateTime::utcOffset | ( | ) | const |
Returns the UTC offset in seconds. If the timeSpec() isn't Qt::OffsetFromUTC, 0 is returned. However, since 0 is a valid UTC offset the return value of this function cannot be used to determine whether a utcOffset() is used or is valid, timeSpec() must be checked.
Likewise, if this QDateTime() is invalid or if timeSpec() isn't Qt::OffsetFromUTC, 0 is returned.
The UTC offset only applies if the timeSpec() is Qt::OffsetFromUTC.
Definition at line 3449 of file qdatetime.cpp.
Referenced by QPatternist::AbstractDateTime::copyTimeSpec(), QPatternist::TimezoneFromAbstractDateTimeFN::extract(), fromString(), QDateTimePrivate::getUTC(), and QPatternist::AbstractDateTime::zoneOffsetToString().
|
friend |
Writes dateTime to the out stream.
Definition at line 3881 of file qdatetime.cpp.
|
friend |
Reads a datetime from the stream in into dateTime.
Definition at line 3900 of file qdatetime.cpp.
|
friend |
Definition at line 292 of file qdatetime.h.
|
private |
Definition at line 294 of file qdatetime.h.
Referenced by addDays(), addMonths(), QDateTimePrivate::addMSecs(), addMSecs(), addSecs(), addYears(), QDate::currentDate(), currentDateTime(), currentDateTimeUtc(), currentMSecsSinceEpoch(), date(), daysTo(), detach(), fromMSecsSinceEpoch(), QDateTimeParser::fromString(), fromTime_t(), isNull(), isValid(), msecsTo(), operator<(), operator=(), operator==(), QDateTime(), secsTo(), setDate(), setMSecsSinceEpoch(), setTime(), setTime_t(), setTimeSpec(), setUtcOffset(), time(), timeSpec(), toMSecsSinceEpoch(), toString(), toTimeSpec(), and utcOffset().