![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore \reentrant More...
#include <qdatetime.h>
Public Member Functions | |
constexpr | QDate () |
Constructs a null date. | |
QDate (int y, int m, int d) | |
Constructs a date with year y, month m and day d. | |
QDate (int y, int m, int d, QCalendar cal) | |
constexpr bool | isNull () const |
Returns true if the date is null; otherwise returns false . | |
constexpr bool | isValid () const |
Returns true if this date is valid; otherwise returns false . | |
int | year () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
int | month () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
int | day () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
int | dayOfWeek () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
int | dayOfYear () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
int | daysInMonth () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
int | daysInYear () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
int | weekNumber (int *yearNum=nullptr) const |
Returns the ISO 8601 week number (1 to 53). | |
int | year (QCalendar cal) const |
Returns the year of this date. | |
int | month (QCalendar cal) const |
Returns the month-number for the date. | |
int | day (QCalendar cal) const |
Returns the day of the month for this date. | |
int | dayOfWeek (QCalendar cal) const |
Returns the weekday (1 = Monday to 7 = Sunday) for this date. | |
int | dayOfYear (QCalendar cal) const |
Returns the day of the year (1 for the first day) for this date. | |
int | daysInMonth (QCalendar cal) const |
Returns the number of days in the month for this date. | |
int | daysInYear (QCalendar cal) const |
Returns the number of days in the year for this date. | |
QDateTime | startOfDay (const QTimeZone &zone) const |
QDateTime | endOfDay (const QTimeZone &zone) const |
QDateTime | startOfDay () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QDateTime | endOfDay () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
bool | setDate (int year, int month, int day) |
bool | setDate (int year, int month, int day, QCalendar cal) |
void | getDate (int *year, int *month, int *day) const |
QDate | addDays (qint64 days) const |
Returns a QDate object containing a date ndays later than the date of this object (or earlier if ndays is negative). | |
QDate | addMonths (int months) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QDate | addYears (int years) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QDate | addMonths (int months, QCalendar cal) const |
Returns a QDate object containing a date nmonths later than the date of this object (or earlier if nmonths is negative). | |
QDate | addYears (int years, QCalendar cal) const |
Returns a QDate object containing a date nyears later than the date of this object (or earlier if nyears is negative). | |
qint64 | daysTo (QDate d) const |
Returns the number of days from this date to d (which is negative if d is earlier than this date). | |
constexpr qint64 | toJulianDay () const |
Converts the date to a Julian day. | |
Static Public Member Functions | |
static QDate | currentDate () |
Returns the system clock's current date. | |
static bool | isValid (int y, int m, int d) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true if the specified date (year, month, and day) is valid in the Gregorian calendar; otherwise returns false . | |
static bool | isLeapYear (int year) |
Returns true if the specified year is a leap year in the Gregorian calendar; otherwise returns false . | |
static constexpr QDate | fromJulianDay (qint64 jd_) |
Converts the Julian day jd to a QDate. | |
Friends | |
class | QDateTime |
class | QDateTimePrivate |
constexpr bool | operator== (QDate lhs, QDate rhs) |
Returns true if lhs and rhs represent the same day, otherwise false . | |
constexpr bool | operator!= (QDate lhs, QDate rhs) |
Returns true if lhs and rhs represent distinct days; otherwise returns false . | |
constexpr bool | operator< (QDate lhs, QDate rhs) |
Returns true if lhs is earlier than rhs; otherwise returns false . | |
constexpr bool | operator<= (QDate lhs, QDate rhs) |
Returns true if lhs is earlier than or equal to rhs; otherwise returns false . | |
constexpr bool | operator> (QDate lhs, QDate rhs) |
Returns true if lhs is later than rhs; otherwise returns false . | |
constexpr bool | operator>= (QDate lhs, QDate rhs) |
Returns true if lhs is later than or equal to rhs; otherwise returns false . | |
Q_CORE_EXPORT QDataStream & | operator<< (QDataStream &, QDate) |
Writes the date to stream out. | |
Q_CORE_EXPORT QDataStream & | operator>> (QDataStream &, QDate &) |
Reads a date from stream in into the date. | |
Related Symbols | |
(Note that these are not member symbols.) | |
QDataStream & | operator<< (QDataStream &out, QDate date) |
Writes the date to stream out. | |
QDataStream & | operator>> (QDataStream &in, QDate &date) |
Reads a date from stream in into the date. | |
\inmodule QtCore \reentrant
The QDate class provides date functions.
A QDate object represents a particular day, regardless of calendar, locale or other settings used when creating it or supplied by the system. It can report the year, month and day of the month that represent the day with respect to the proleptic Gregorian calendar or any calendar supplied as a QCalendar object. QDate objects should be passed by value rather than by reference to const; they simply package qint64
.
A QDate object is typically created by giving the year, month, and day numbers explicitly. Note that QDate interprets year numbers less than 100 as presented, i.e., as years 1 through 99, without adding any offset. The static function currentDate() creates a QDate object containing the date read from the system clock. An explicit date can also be set using setDate(). The fromString() function returns a QDate given a string and a date format which is used to interpret the date within the string.
The year(), month(), and day() functions provide access to the year, month, and day numbers. When more than one of these values is needed, it is more efficient to call QCalendar::partsFromDate(), to save repeating (potentially expensive) calendrical calculations.
Also, dayOfWeek() and dayOfYear() functions are provided. The same information is provided in textual format by toString(). QLocale can map the day numbers to names, QCalendar can map month numbers to names.
QDate provides a full set of operators to compare two QDate objects where smaller means earlier, and larger means later.
You can increment (or decrement) a date by a given number of days using addDays(). Similarly you can use addMonths() and addYears(). The daysTo() function returns the number of days between two dates.
The daysInMonth() and daysInYear() functions return how many days there are in this date's month and year, respectively. The isLeapYear() function indicates whether a date is in a leap year. QCalendar can also supply this information, in some cases more conveniently.
Definition at line 26 of file qdatetime.h.
|
inlineconstexpr |
Constructs a null date.
Null dates are invalid.
Definition at line 30 of file qdatetime.h.
Referenced by addDays(), addMonths(), addMonths(), addYears(), addYears(), and setDate().
QDate::QDate | ( | int | y, |
int | m, | ||
int | d | ||
) |
Constructs a date with year y, month m and day d.
The date is understood in terms of the Gregorian calendar. If the specified date is invalid, the date is not set and isValid() returns false
.
Definition at line 436 of file qdatetime.cpp.
References d, QtPrivate::DateTimeConstants::JulianDayMax, QtPrivate::DateTimeConstants::JulianDayMin, and QGregorianCalendar::julianFromParts().
QDate::QDate | ( | int | y, |
int | m, | ||
int | d, | ||
QCalendar | cal | ||
) |
Definition at line 443 of file qdatetime.cpp.
References d, and QCalendar::dateFromParts().
Returns a QDate object containing a date ndays later than the date of this object (or earlier if ndays is negative).
Returns a null date if the current date is invalid or the new date is out of range.
Definition at line 1362 of file qdatetime.cpp.
References QDate(), fromJulianDay(), isNull(), Q_UNLIKELY, and qAddOverflow().
Referenced by calculateDowDate(), calculatePosixDate(), QtPrivate::QCalendarModel::dateForCell(), endOfDay(), fromDate(), fromTimeStamp(), QQuickWeekNumberModelPrivate::init(), QtPrivate::QCalendarView::moveCursor(), QQuickMonthModelPrivate::populate(), startOfDay(), and weekNumber().
QDate QDate::addMonths | ( | int | months | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 1440 of file qdatetime.cpp.
References QDate(), fixedDate(), isNull(), QGregorianCalendar::partsFromJulian(), and Q_ASSERT.
Referenced by QCalendarWidgetPrivate::_q_monthChanged(), QCalendarWidgetPrivate::_q_nextMonthClicked(), QCalendarWidgetPrivate::_q_prevMonthClicked(), and QtPrivate::QCalendarView::moveCursor().
Returns a QDate object containing a date nmonths later than the date of this object (or earlier if nmonths is negative).
Uses cal as calendar, if supplied, else the Gregorian calendar.
Definition at line 1408 of file qdatetime.cpp.
References QDate(), fixedDate(), QCalendar::hasYearZero(), isValid(), QCalendar::monthsInYear(), QCalendar::partsFromDate(), and Q_ASSERT.
QDate QDate::addYears | ( | int | years | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 1505 of file qdatetime.cpp.
References QDate(), fixedDate(), isNull(), and QGregorianCalendar::partsFromJulian().
Referenced by QCalendarWidgetPrivate::_q_yearEditingFinished(), qlocationutils_readRmc(), and QAsn1Element::toDateTime().
Returns a QDate object containing a date nyears later than the date of this object (or earlier if nyears is negative).
Uses cal as calendar, if supplied, else the Gregorian calendar.
Definition at line 1482 of file qdatetime.cpp.
References QDate(), fixedDate(), QCalendar::hasYearZero(), isValid(), and QCalendar::partsFromDate().
|
static |
Returns the system clock's current date.
Referenced by QQuickMonthModelPrivate::QQuickMonthModelPrivate(), QQuickWeekNumberModelPrivate::QQuickWeekNumberModelPrivate(), MainWindow::insertCalendar(), macTimeToString(), main(), QQuickMonthModelPrivate::populate(), and QCalendarWidget::showToday().
int QDate::day | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 636 of file qdatetime.cpp.
References isValid(), and QGregorianCalendar::partsFromJulian().
Referenced by QOCIDateTime::QOCIDateTime(), QtPrivate::QCalendarModel::cellForDate(), QtPrivate::QCalendarModel::columnForFirstOfMonth(), QtPrivate::QCalendarModel::data(), QQuickMonthModel::data(), QtPrivate::QCalendarModel::dateForCell(), QDB2Result::exec(), QODBCResult::exec(), QDB2Driver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QODBCDriver::formatValue(), getDate(), isValid(), macDateToString(), operator<<(), QCalendarWidget::setCurrentPage(), setDate(), setDate(), QtPrivate::QCalendarDayValidator::setDate(), QDateTimeParser::setDigit(), QGstreamerMetaData::setMetaData(), QtPrivate::QCalendarDayValidator::text(), toMySqlDate(), QSystemLocalePrivate::toString(), writeMSDosDate(), and QGregorianCalendar::yearSharingWeekDays().
int QDate::day | ( | QCalendar | cal | ) | const |
Returns the day of the month for this date.
Uses cal as calendar if supplied, else the Gregorian calendar (for which the return ranges from 1 to 31). Returns 0 if the date is invalid.
Definition at line 622 of file qdatetime.cpp.
References QCalendar::YearMonthDay::day, isValid(), and QCalendar::partsFromDate().
int QDate::dayOfWeek | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 668 of file qdatetime.cpp.
References isValid(), and QGregorianCalendar::weekDayOfJulian().
Referenced by calculateDowDate(), QQuickWeekNumberModelPrivate::init(), MainWindow::insertCalendar(), QQuickMonthModelPrivate::populate(), QtPrivate::QCalendarDayValidator::text(), and weekNumber().
int QDate::dayOfWeek | ( | QCalendar | cal | ) | const |
Returns the weekday (1 = Monday to 7 = Sunday) for this date.
Uses cal as calendar if supplied, else the Gregorian calendar. Returns 0 if the date is invalid. Some calendars may give special meaning (e.g. intercallary days) to values greater than 7.
Definition at line 656 of file qdatetime.cpp.
References QCalendar::dayOfWeek(), and isNull().
int QDate::dayOfYear | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 696 of file qdatetime.cpp.
References isValid(), QGregorianCalendar::julianFromParts(), and year().
Referenced by weekNumber().
int QDate::dayOfYear | ( | QCalendar | cal | ) | const |
Returns the day of the year (1 for the first day) for this date.
Uses cal as calendar if supplied, else the Gregorian calendar. Returns 0 if either the date or the first day of its year is invalid.
Definition at line 682 of file qdatetime.cpp.
References QCalendar::dateFromParts(), daysTo(), isValid(), and year().
int QDate::daysInMonth | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 729 of file qdatetime.cpp.
References isValid(), QGregorianCalendar::monthLength(), and QGregorianCalendar::partsFromJulian().
Referenced by QDateTimeParser::absoluteMax(), and MainWindow::insertCalendar().
int QDate::daysInMonth | ( | QCalendar | cal | ) | const |
Returns the number of days in the month for this date.
Uses cal as calendar if supplied, else the Gregorian calendar (for which the result ranges from 28 to 31). Returns 0 if the date is invalid.
Definition at line 715 of file qdatetime.cpp.
References QCalendar::daysInMonth(), isValid(), and QCalendar::partsFromDate().
int QDate::daysInYear | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 760 of file qdatetime.cpp.
References isValid(), QGregorianCalendar::leapTest(), and year().
int QDate::daysInYear | ( | QCalendar | cal | ) | const |
Returns the number of days in the year for this date.
Uses cal as calendar if supplied, else the Gregorian calendar (for which the result is 365 or 366). Returns 0 if the date is invalid.
Definition at line 748 of file qdatetime.cpp.
References QCalendar::daysInYear(), isNull(), and year().
Returns the number of days from this date to d (which is negative if d is earlier than this date).
Returns 0 if either date is invalid.
Example:
Definition at line 1536 of file qdatetime.cpp.
Referenced by QtPrivate::QCalendarModel::cellForDate(), dayOfYear(), QDateTime::daysTo(), toDate(), toTimeStamp(), and QCalendarWidgetPrivate::updateCurrentPage().
QDateTime QDate::endOfDay | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 1110 of file qdatetime.cpp.
References endOfDay(), and QTimeZone::LocalTime.
Referenced by endOfDay().
Returns the end-moment of the day.
When a day ends depends on a how time is described: each day starts and ends earlier for those in time-zones further west and later for those in time-zones further east. The time representation to use can be specified by an optional time zone. The default time representation is the system's local time.
Usually, the end of the day is one millisecond before the midnight, 24:00: however, if a time-zone transition causes the given date to skip over that moment (e.g. a DST spring-forward skipping over 23:00 and the following hour), the actual latest time in the day is returned. This can only arise when the time representation is a time-zone or local time.
When zone has a timeSpec() of Qt::OffsetFromUTC or Qt::UTC, the time representation has no transitions so the end of the day is QTime(23, 59, 59, 999).
In the rare case of a date that was entirely skipped (this happens when a zone east of the international date-line switches to being west of it), the return shall be invalid. Passing an invalid time-zone as zone will also produce an invalid result, as shall dates that end outside the range representable by QDateTime.
Definition at line 1081 of file qdatetime.cpp.
References addDays(), at, End, inDateTimeRange(), QDateTime::isValid(), QTimeZone::isValid(), Q_LIKELY, QDateTime, QTimeZone::timeSpec(), Qt::TimeZone, and toLatest().
Referenced by QDateTimeEditPrivate::updateTimeZone().
Converts the Julian day jd to a QDate.
Definition at line 159 of file qdatetime.h.
Referenced by addDays(), QCalendarWidget::clearMinimumDate(), QCalendar::dateFromParts(), fixedDate(), getDateTime(), and msecsToDate().
void QDate::getDate | ( | int * | year, |
int * | month, | ||
int * | day | ||
) | const |
Extracts the date's year, month, and day, and assigns them to year, *month, and *day. The pointers may be null.
Returns 0 if the date is invalid.
{const}.Definition at line 1337 of file qdatetime.cpp.
References QCalendar::YearMonthDay::day, day(), QCalendar::YearMonthDay::isValid(), isValid(), QCalendar::YearMonthDay::month, month(), ok, QGregorianCalendar::partsFromJulian(), QCalendar::YearMonthDay::year, and year().
|
static |
Returns true
if the specified year is a leap year in the Gregorian calendar; otherwise returns false
.
Definition at line 1786 of file qdatetime.cpp.
References QGregorianCalendar::leapTest().
Referenced by calculatePosixDate().
|
inlineconstexpr |
Returns true
if the date is null; otherwise returns false
.
A null date is invalid.
Definition at line 85 of file qdatetime.h.
Referenced by addDays(), addMonths(), addYears(), dayOfWeek(), daysInYear(), daysTo(), and QCalendarWidget::setDateTextFormat().
|
inlineconstexpr |
Returns true
if this date is valid; otherwise returns false
.
Definition at line 86 of file qdatetime.h.
Referenced by QDateTimeEdit::QDateTimeEdit(), actualDate(), addMonths(), addYears(), QtPrivate::QCalendarModel::cellForDate(), QQuickMonthGridPrivate::clearPress(), QtPrivate::QCalendarModel::data(), QtPrivate::QCalendarModel::dateForCell(), dateFromString(), QCalendarBackend::dateTimeToString(), day(), day(), dayOfWeek(), QCalendar::dayOfWeek(), dayOfYear(), dayOfYear(), daysInMonth(), daysInMonth(), daysInYear(), QtPrivate::QCalendarModel::flags(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QSqlDriver::formatValue(), QQuickCalendarModelPrivate::getCount(), getDate(), QtPrivate::QCalendarView::handleMouseEvent(), QQuickMonthGridPrivate::handlePress(), month(), month(), QtPrivate::QCalendarView::mouseMoveEvent(), QtPrivate::QCalendarView::mousePressEvent(), QtPrivate::QCalendarView::mouseReleaseEvent(), msecsTo(), QNmeaRealTimeReader::notifyNewUpdate(), QNmeaPositionInfoSourcePrivate::notifyNewUpdate(), operator<<(), QtPrivate::QCalendarDelegate::paint(), parseDateString(), QCalendar::partsFromDate(), processSentence(), qlocationutils_readRmc(), QNmeaRealTimeReader::readAvailableData(), QtPrivate::QCalendarModel::referenceDate(), setDate(), QDateTimeEdit::setDate(), QCalendarWidget::setDateRange(), QDateTimeEdit::setDateRange(), setDateTime(), QDateTimeParser::setDigit(), QCalendarWidget::setMaximumDate(), QDateTimeEdit::setMaximumDate(), QCalendarWidget::setMinimumDate(), QCalendarWidget::setSelectedDate(), QLocale::toString(), QLocale::toString(), QCalendarWidget::updateCell(), QCalendarWidgetPrivate::updateCurrentPage(), QQuickMonthGridPrivate::updatePress(), validatePosixRule(), weekNumber(), year(), and year().
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true
if the specified date (year, month, and day) is valid in the Gregorian calendar; otherwise returns false
.
Example:
Definition at line 1772 of file qdatetime.cpp.
References day(), month(), QGregorianCalendar::validParts(), and year().
int QDate::month | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 603 of file qdatetime.cpp.
References isValid(), and QGregorianCalendar::partsFromJulian().
Referenced by QOCIDateTime::QOCIDateTime(), QQuickMonthModelPrivate::QQuickMonthModelPrivate(), QQuickWeekNumberModelPrivate::QQuickWeekNumberModelPrivate(), QCalendarWidgetPrivate::_q_monthChanged(), QCalendarWidgetPrivate::_q_slotChangeDate(), calculateDowDate(), QCalendarWidgetPrivate::createNavigationBar(), QQuickMonthModel::data(), QDB2Result::exec(), QODBCResult::exec(), QtPrivate::QCalendarModel::formatForCell(), QDB2Driver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QODBCDriver::formatValue(), getDate(), MainWindow::insertCalendar(), isValid(), macDateToString(), operator<<(), QDateTimeParser::parse(), QtPrivate::QCalendarModel::setCalendar(), setDate(), setDate(), QtPrivate::QCalendarMonthValidator::setDate(), QCalendarWidget::setDateRange(), QDateTimeParser::setDigit(), QCalendarWidget::setMaximumDate(), QGstreamerMetaData::setMetaData(), QCalendarWidget::setMinimumDate(), QCalendarWidget::setSelectedDate(), QCalendarWidget::showSelectedDate(), QCalendarWidget::showToday(), toMySqlDate(), QSystemLocalePrivate::toString(), QCalendarWidgetPrivate::updateCurrentPage(), QCalendarWidgetPrivate::updateMonthMenu(), writeMSDosDate(), and QGregorianCalendar::yearSharingWeekDays().
int QDate::month | ( | QCalendar | cal | ) | const |
Returns the month-number for the date.
Numbers the months of the year starting with 1 for the first. Uses cal as calendar if supplied, else the Gregorian calendar, for which the month numbering is as follows:
\list
Returns 0 if the date is invalid. Note that some calendars may have more than 12 months in some years.
Definition at line 589 of file qdatetime.cpp.
References isValid(), QCalendar::YearMonthDay::month, and QCalendar::partsFromDate().
bool QDate::setDate | ( | int | year, |
int | month, | ||
int | day | ||
) |
Sets this to represent the date, in the Gregorian calendar, with the given year, month and day numbers. Returns true if the resulting date is valid, otherwise it sets this to represent an invalid date and returns false.
Definition at line 1301 of file qdatetime.cpp.
References day(), QGregorianCalendar::julianFromParts(), month(), and year().
Referenced by operator>>(), qlocationutils_readZda(), and QAsn1Element::toDateTime().
bool QDate::setDate | ( | int | year, |
int | month, | ||
int | day, | ||
QCalendar | cal | ||
) |
Sets this to represent the date, in the given calendar cal, with the given year, month and day numbers. Returns true if the resulting date is valid, otherwise it sets this to represent an invalid date and returns false.
Definition at line 1319 of file qdatetime.cpp.
References QDate(), day(), isValid(), month(), and year().
QDateTime QDate::startOfDay | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 960 of file qdatetime.cpp.
References QTimeZone::LocalTime, and startOfDay().
Referenced by startOfDay().
Returns the start-moment of the day.
When a day starts depends on a how time is described: each day starts and ends earlier for those in time-zones further west and later for those in time-zones further east. The time representation to use can be specified by an optional time zone. The default time representation is the system's local time.
Usually, the start of the day is midnight, 00:00: however, if a time-zone transition causes the given date to skip over that midnight (e.g. a DST spring-forward skipping over the first hour of the day day), the actual earliest time in the day is returned. This can only arise when the time representation is a time-zone or local time.
When zone has a timeSpec() of is Qt::OffsetFromUTC or Qt::UTC, the time representation has no transitions so the start of the day is QTime(0, 0).
In the rare case of a date that was entirely skipped (this happens when a zone east of the international date-line switches to being west of it), the return shall be invalid. Passing an invalid time-zone as zone will also produce an invalid result, as shall dates that start outside the range representable by QDateTime.
Definition at line 931 of file qdatetime.cpp.
References addDays(), at, inDateTimeRange(), QDateTime::isValid(), QTimeZone::isValid(), Q_LIKELY, QDateTime, Start, QTimeZone::timeSpec(), Qt::TimeZone, and toEarliest().
Referenced by QDateTimeParser::fromString(), QDateTimeEditPrivate::init(), QV4::Date::init(), and QDateTimeEditPrivate::updateTimeZone().
|
inlineconstexpr |
Converts the date to a Julian day.
Definition at line 161 of file qdatetime.h.
Referenced by QCalendarBackend::dateTimeToString(), QCalendar::dayOfWeek(), QDateTimeParser::parse(), QCalendar::partsFromDate(), setDateTime(), and timeToMSecs().
int QDate::weekNumber | ( | int * | yearNumber = nullptr | ) | const |
Returns the ISO 8601 week number (1 to 53).
Returns 0 if the date is invalid. Otherwise, returns the week number for the date. If yearNumber is not \nullptr (its default), stores the year as {yearNumber}.
In accordance with ISO 8601, each week falls in the year to which most of its days belong, in the Gregorian calendar. As ISO 8601's week starts on Monday, this is the year in which the week's Thursday falls. Most years have 52 weeks, but some have 53.
Definition at line 784 of file qdatetime.cpp.
References addDays(), dayOfWeek(), dayOfYear(), isValid(), and year().
Referenced by QtPrivate::QCalendarModel::data(), QQuickMonthModel::data(), and QQuickWeekNumberModelPrivate::init().
int QDate::year | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 551 of file qdatetime.cpp.
References isValid(), and QGregorianCalendar::partsFromJulian().
Referenced by QOCIDateTime::QOCIDateTime(), QQuickMonthModelPrivate::QQuickMonthModelPrivate(), QQuickWeekNumberModelPrivate::QQuickWeekNumberModelPrivate(), QCalendarWidgetPrivate::_q_slotChangeDate(), QCalendarWidgetPrivate::_q_yearEditingFinished(), QCalendarWidgetPrivate::createNavigationBar(), QQuickMonthModel::data(), dayOfYear(), dayOfYear(), daysInYear(), daysInYear(), QDB2Result::exec(), QODBCResult::exec(), QDB2Driver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QODBCDriver::formatValue(), getDate(), MainWindow::insertCalendar(), isValid(), macDateToString(), operator<<(), QDateTimeParser::parse(), QtPrivate::QCalendarModel::setCalendar(), setDate(), setDate(), QtPrivate::QCalendarYearValidator::setDate(), QCalendarWidget::setDateRange(), QDateTimeParser::setDigit(), QCalendarWidget::setMaximumDate(), QGstreamerMetaData::setMetaData(), QCalendarWidget::setMinimumDate(), QCalendarWidget::setSelectedDate(), QCalendarWidget::showSelectedDate(), QCalendarWidget::showToday(), QtPrivate::QCalendarYearValidator::text(), QAsn1Element::toDateTime(), toMySqlDate(), QSystemLocalePrivate::toString(), QCalendarWidgetPrivate::updateCurrentPage(), QCalendarWidgetPrivate::updateMonthMenu(), weekNumber(), writeMSDosDate(), and QGregorianCalendar::yearSharingWeekDays().
int QDate::year | ( | QCalendar | cal | ) | const |
Returns the year of this date.
Uses cal as calendar, if supplied, else the Gregorian calendar.
Returns 0 if the date is invalid. For some calendars, dates before their first year may all be invalid.
If using a calendar which has a year 0, check using isValid() if the return is 0. Such calendars use negative year numbers in the obvious way, with year 1 preceded by year 0, in turn preceded by year -1 and so on.
Some calendars, despite having no year 0, have a conventional numbering of the years before their first year, counting backwards from 1. For example, in the proleptic Gregorian calendar, successive years before 1 CE (the first year) are identified as 1 BCE, 2 BCE, 3 BCE and so on. For such calendars, negative year numbers are used to indicate these years before year 1, with -1 indicating the year before 1.
Definition at line 537 of file qdatetime.cpp.
References isValid(), QCalendar::partsFromDate(), and QCalendar::YearMonthDay::year.
Returns true
if lhs and rhs represent distinct days; otherwise returns false
.
Definition at line 176 of file qdatetime.h.
Returns true
if lhs is earlier than rhs; otherwise returns false
.
Definition at line 177 of file qdatetime.h.
|
friend |
Writes the date to stream out.
Definition at line 5413 of file qdatetime.cpp.
|
related |
Writes the date to stream out.
Definition at line 5413 of file qdatetime.cpp.
Returns true
if lhs is earlier than or equal to rhs; otherwise returns false
.
Definition at line 178 of file qdatetime.h.
Returns true
if lhs and rhs represent the same day, otherwise false
.
Definition at line 175 of file qdatetime.h.
Returns true
if lhs is later than rhs; otherwise returns false
.
Definition at line 179 of file qdatetime.h.
Returns true
if lhs is later than or equal to rhs; otherwise returns false
.
Definition at line 180 of file qdatetime.h.
|
friend |
Reads a date from stream in into the date.
Definition at line 5429 of file qdatetime.cpp.
|
related |
Reads a date from stream in into the date.
Definition at line 5429 of file qdatetime.cpp.
|
friend |
Definition at line 172 of file qdatetime.h.
Referenced by endOfDay(), and startOfDay().
|
friend |
Definition at line 173 of file qdatetime.h.