![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtCore \reentrant More...
#include <qdatetime.h>
Public Types | |
| using | difference_type = qint64 |
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 |
| int | month () const |
| int | day () const |
| int | dayOfWeek () const |
| int | dayOfYear () const |
| int | daysInMonth () const |
| int | daysInYear () const |
| int | weekNumber (int *yearNum=nullptr) const |
| Returns the ISO 8601 week number (1 to 53). | |
| int | year (QCalendar cal) const |
| int | month (QCalendar cal) const |
| int | day (QCalendar cal) const |
| int | dayOfWeek (QCalendar cal) const |
| int | dayOfYear (QCalendar cal) const |
| int | daysInMonth (QCalendar cal) const |
| int | daysInYear (QCalendar cal) const |
| QDateTime | startOfDay (const QTimeZone &zone) const |
| QDateTime | endOfDay (const QTimeZone &zone) const |
| QDateTime | startOfDay () const |
| QDateTime | endOfDay () const |
| 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 |
| QDate | addYears (int years) const |
| QDate | addMonths (int months, QCalendar cal) const |
| QDate | addYears (int years, QCalendar cal) const |
| 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) |
| 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 | QDateTimeParser |
| class | QDateTimePrivate |
| constexpr bool | comparesEqual (const QDate &lhs, const QDate &rhs) noexcept |
| constexpr Qt::strong_ordering | compareThreeWay (const QDate &lhs, const QDate &rhs) noexcept |
| QDate & | operator++ (QDate &date) noexcept |
| QDate & | operator-- (QDate &date) noexcept |
| QDate | operator++ (QDate &date, int) noexcept |
| QDate | operator-- (QDate &date, int) noexcept |
| 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.) | |
| dayOfYear | |
| startOfDay | |
| endOfDay | |
| dayOfYear | |
| startOfDay | |
| endOfDay | |
\inmodule QtCore \reentrant
The QDate class provides date functions.
\compares strong \compareswith strong std::chrono::year_month_day std::chrono::year_month_day_last \ std::chrono::year_month_weekday std::chrono::year_month_weekday_last These comparison operators are only available when using C++20. \endcompareswith
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 28 of file qdatetime.h.
| using QDate::difference_type = qint64 |
Definition at line 32 of file qdatetime.h.
|
inlineconstexpr |
| 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 448 of file qdatetime.cpp.
| QDate::QDate | ( | int | y, |
| int | m, | ||
| int | d, | ||
| QCalendar | cal ) |
Definition at line 455 of file qdatetime.cpp.
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 1423 of file qdatetime.cpp.
|
nodiscard |
Definition at line 1502 of file qdatetime.cpp.
Definition at line 1470 of file qdatetime.cpp.
|
nodiscard |
Definition at line 1569 of file qdatetime.cpp.
Definition at line 1546 of file qdatetime.cpp.
|
static |
Returns the system clock's current date.
| int QDate::day | ( | ) | const |
Definition at line 655 of file qdatetime.cpp.
| int QDate::day | ( | QCalendar | cal | ) | const |
Definition at line 641 of file qdatetime.cpp.
| int QDate::dayOfWeek | ( | ) | const |
Definition at line 689 of file qdatetime.cpp.
| int QDate::dayOfWeek | ( | QCalendar | cal | ) | const |
Definition at line 677 of file qdatetime.cpp.
| int QDate::dayOfYear | ( | ) | const |
Definition at line 719 of file qdatetime.cpp.
| int QDate::dayOfYear | ( | QCalendar | cal | ) | const |
Definition at line 705 of file qdatetime.cpp.
| int QDate::daysInMonth | ( | ) | const |
Definition at line 754 of file qdatetime.cpp.
| int QDate::daysInMonth | ( | QCalendar | cal | ) | const |
Definition at line 740 of file qdatetime.cpp.
| int QDate::daysInYear | ( | ) | const |
Definition at line 787 of file qdatetime.cpp.
| int QDate::daysInYear | ( | QCalendar | cal | ) | const |
Definition at line 775 of file qdatetime.cpp.
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 1600 of file qdatetime.cpp.
| QDateTime QDate::endOfDay | ( | ) | const |
Definition at line 1150 of file qdatetime.cpp.
Definition at line 1120 of file qdatetime.cpp.
Converts the Julian day jd to a QDate.
Definition at line 172 of file qdatetime.h.
| 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 1398 of file qdatetime.cpp.
|
static |
Returns true if the specified year is a leap year in the Gregorian calendar; otherwise returns false.
Definition at line 1957 of file qdatetime.cpp.
|
inlineconstexpr |
Returns true if the date is null; otherwise returns false.
A null date is invalid.
Definition at line 73 of file qdatetime.h.
|
inlineconstexpr |
Returns true if this date is valid; otherwise returns false.
Definition at line 74 of file qdatetime.h.
|
static |
Definition at line 1943 of file qdatetime.cpp.
| int QDate::month | ( | ) | const |
Definition at line 620 of file qdatetime.cpp.
| int QDate::month | ( | QCalendar | cal | ) | const |
Definition at line 606 of file qdatetime.cpp.
| 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 1362 of file qdatetime.cpp.
| 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 1380 of file qdatetime.cpp.
| QDateTime QDate::startOfDay | ( | ) | const |
Definition at line 994 of file qdatetime.cpp.
Definition at line 963 of file qdatetime.cpp.
|
inlineconstexpr |
Converts the date to a Julian day.
Definition at line 174 of file qdatetime.h.
| 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 811 of file qdatetime.cpp.
| int QDate::year | ( | ) | const |
Definition at line 566 of file qdatetime.cpp.
| int QDate::year | ( | QCalendar | cal | ) | const |
Definition at line 552 of file qdatetime.cpp.
Definition at line 209 of file qdatetime.h.
|
friend |
Definition at line 212 of file qdatetime.h.
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
The prefix {++} operator, adds a day to date and returns a reference to the modified date object.
Definition at line 216 of file qdatetime.h.
The postfix {++} operator, adds a day to date and returns a copy of date with the previous date.
Definition at line 228 of file qdatetime.h.
The prefix {–} operator, subtracts a day from date and returns a reference to the modified date object.
Definition at line 222 of file qdatetime.h.
The postfix {–} operator, subtracts a day from date and returns a copy of date with the next date.
Definition at line 235 of file qdatetime.h.
|
friend |
Writes the date to stream out.
Definition at line 6112 of file qdatetime.cpp.
|
friend |
Reads a date from stream in into the date.
Definition at line 6128 of file qdatetime.cpp.
|
friend |
Definition at line 205 of file qdatetime.h.
|
friend |
Definition at line 206 of file qdatetime.h.
|
friend |
Definition at line 207 of file qdatetime.h.
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.