QDate() | |
QDate(int y, int m, int d) | |
QDate | addDays(qint64 ndays) const |
QDate | addMonths(int nmonths) const |
QDate | addYears(int nyears) const |
int | day() const |
int | dayOfWeek() const |
int | dayOfYear() const |
int | daysInMonth() const |
int | daysInYear() const |
qint64 | daysTo(const QDate &d) const |
void | getDate(int *year, int *month, int *day) const |
bool | isNull() const |
bool | isValid() const |
int | month() const |
bool | setDate(int year, int month, int day) |
qint64 | toJulianDay() const |
QString | toString(const QString &format) const |
QString | toString(Qt::DateFormat format = Qt::TextDate) const |
int | weekNumber(int *yearNumber = Q_NULLPTR) const |
int | year() const |
bool | operator!=(const QDate &d) const |
bool | operator<(const QDate &d) const |
bool | operator<=(const QDate &d) const |
bool | operator==(const QDate &d) const |
bool | operator>(const QDate &d) const |
bool | operator>=(const QDate &d) const |
QDate | |
QDate | fromJulianDay(qint64 jd) |
QDate | fromString(const QString &string, Qt::DateFormat format = Qt::TextDate) |
QDate | fromString(const QString &string, const QString &format) |
bool | isLeapYear(int year) |
bool | isValid(int year, int month, int day) |
QString | longDayName(int weekday, MonthNameType type = DateFormat) |
QString | longMonthName(int month, MonthNameType type = DateFormat) |
QString | shortDayName(int weekday, MonthNameType type = DateFormat) |
QString | shortMonthName(int month, MonthNameType type = DateFormat) |
QDataStream & | operator<<(QDataStream &out, const QDate &date) |
QDataStream & | operator>>(QDataStream &in, QDate &date) |
The QDate class provides date functions.
A QDate object contains a calendar date, i.e. year, month, and day numbers, in the Gregorian calendar. It can read the current date from the system clock. It provides functions for comparing dates, and for manipulating dates. For example, it is possible to add and subtract days, months, and years to dates.
A QDate object is typically created by giving the year, month, and day numbers explicitly. Note that QDate interprets two digit years as is, i.e., years 0 - 99. A QDate can also be constructed with the static function currentDate(), which creates a QDate object containing the system clock's date. 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. Also, dayOfWeek() and dayOfYear() functions are provided. The same information is provided in textual format by the toString(), shortDayName(), longDayName(), shortMonthName(), and longMonthName() functions.
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.
No Year 0
There is no year 0. Dates in that year are considered invalid. The year -1 is the year "1 before Christ" or "1 before current era." The day before 1 January 1 CE is 31 December 1 BCE.
Range of Valid Dates
Dates are stored internally as a Julian Day number, an integer count of every day in a contiguous range, with 24 November 4714 BCE in the Gregorian calendar being Julian Day 0 (1 January 4713 BCE in the Julian calendar). As well as being an efficient and accurate way of storing an absolute date, it is suitable for converting a Date into other calendar systems such as Hebrew, Islamic or Chinese. The Julian Day number can be obtained using QDate::toJulianDay() and can be set using QDate::fromJulianDay().
The range of dates able to be stored by QDate as a Julian Day number is for technical reasons limited to between -784350574879 and 784354017364, which means from before 2 billion BCE to after 2 billion CE.