The QDate class provides date functions. More...
#include <qdatetime.h>
Public Member Functions | |
QDate () | |
QDate (int y, int m, int d) | |
virtual | ~QDate () |
bool | isNull () const |
bool | isValid () const |
int | year () const |
int | month () const |
int | day () const |
int | dayOfWeek () const |
int | dayOfYear () const |
int | daysInMonth () const |
int | daysInYear () const |
virtual QString | monthName (int month) const |
virtual QString | dayName (int weekday) const |
QString | toString () const |
bool | setYMD (int y, int m, int d) |
QDate | addDays (int days) const |
int | daysTo (const QDate &) 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 |
Static Public Member Functions | |
static QDate | currentDate () |
static bool | isValid (int y, int m, int d) |
static bool | leapYear (int year) |
Static Protected Member Functions | |
static uint | greg2jul (int y, int m, int d) |
static void | jul2greg (uint jd, int &y, int &m, int &d) |
Private Attributes | |
uint | jd |
Static Private Attributes | |
static const char *const | monthNames [] |
static const char *const | weekdayNames [] |
Friends | |
class | QDateTime |
Q_EXPORT QDataStream & | operator<< (QDataStream &, const QDate &) |
Q_EXPORT QDataStream & | operator>> (QDataStream &, QDate &) |
The QDate class provides date functions.
A QDate object contains a calendar date, i.e. year, month, and day numbers in the modern western (Gregorian) calendar. It can read the current date from the system clock. It provides functions for comparing dates and for manipulating a date by adding a number of days.
A QDate object is typically created either by giving the year, month and day numbers explicitly, or by using the static function currentDate(), which makes a QDate object which contains the system's clock date. An explicit date can also be set using setYMD().
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(), dayName(), and monthName() functions.
QDate provides a full set of operators to compare two QDate objects. A date is considered smaller than another if it is earlier than the other.
The date a given number of days later than a given date can be found using the addDays() function. Correspondingly, the number of days between two dates can be found using the daysTo() function.
The daysInMonth() and daysInYear() functions tell how many days there are in this date's month and year, respectively. The isLeapYear() function tells whether this date is in a leap year.
Note that QDate may not be used for date calculations for dates in the remote past, i.e. prior to the introduction of the Gregorian calendar. This calendar was adopted by England Sep. 14. 1752 (hence this is the earliest valid QDate), and subsequently by most other western countries, until 1923.
The end of time is reached around 8000AD, by which time we expect Qt to be obsolete.
Definition at line 50 of file qdatetime.h.
|
inline |
QDate::QDate | ( | int | y, |
int | m, | ||
int | d | ||
) |
Constructs a date with the year y, month m and day d.
y must be in the range 1752-ca. 8000, m must be in the range 1-12, and d must be in the range 1-31. Exception: if y is in the range 0-99, it is interpreted as 1900-1999.
Definition at line 155 of file qdatetime.cpp.
|
inlinevirtual |
Definition at line 55 of file qdatetime.h.
QDate QDate::addDays | ( | int | ndays | ) | const |
Returns a QDate object containing a date ndays later than the date of this object (or earlier if ndays is negative).
Definition at line 370 of file qdatetime.cpp.
|
static |
Returns the current date, as reported by the system clock.
Definition at line 437 of file qdatetime.cpp.
int QDate::day | ( | ) | const |
Returns the day of the month (1..31) of this date.
Definition at line 215 of file qdatetime.cpp.
|
virtual |
Returns the name of the weekday.
Weekday 1 == "Mon", day 2 == "Tue" etc.
Definition at line 302 of file qdatetime.cpp.
int QDate::dayOfWeek | ( | ) | const |
Returns the weekday (Monday=1 .. Sunday=7) for this date.
Definition at line 228 of file qdatetime.cpp.
int QDate::dayOfYear | ( | ) | const |
Returns the day of the year (1..365) for this date.
Definition at line 239 of file qdatetime.cpp.
int QDate::daysInMonth | ( | ) | const |
Returns the number of days in the month (28..31) for this date.
Definition at line 250 of file qdatetime.cpp.
int QDate::daysInYear | ( | ) | const |
Returns the number of days in the year (365 or 366) for this date.
Definition at line 266 of file qdatetime.cpp.
int QDate::daysTo | ( | const QDate & | d | ) | const |
Returns the number of days from this date to d (which is negative if d is earlier than this date).
Definition at line 392 of file qdatetime.cpp.
|
staticprotected |
Definition at line 504 of file qdatetime.cpp.
|
inline |
Returns TRUE if the date is null. A null date is invalid.
Definition at line 57 of file qdatetime.h.
bool QDate::isValid | ( | ) | const |
|
static |
Returns TRUE if the specified date (year y, month m and day d) is valid.
Note that a y value in the range 00-99 is interpreted as 1900-1999.
Definition at line 477 of file qdatetime.cpp.
|
staticprotected |
Definition at line 528 of file qdatetime.cpp.
|
static |
int QDate::month | ( | ) | const |
Returns the month (January=1 .. December=12) of this date.
Definition at line 202 of file qdatetime.cpp.
|
virtual |
Returns the name of the month.
Month 1 == "Jan", month 2 == "Feb" etc.
Definition at line 282 of file qdatetime.cpp.
Returns TRUE if this date is different from d, or FALSE if they are equal.
Definition at line 79 of file qdatetime.h.
Returns TRUE if this date is earlier than d, otherwise FALSE.
Definition at line 80 of file qdatetime.h.
Returns TRUE if this date is earlier than or equal to d, otherwise FALSE.
Definition at line 81 of file qdatetime.h.
Returns TRUE if this date is equal to d, or FALSE if they are different.
Definition at line 78 of file qdatetime.h.
Returns TRUE if this date is later than d, otherwise FALSE.
Definition at line 82 of file qdatetime.h.
Returns TRUE if this date is later than or equal to d, otherwise FALSE.
Definition at line 83 of file qdatetime.h.
bool QDate::setYMD | ( | int | y, |
int | m, | ||
int | d | ||
) |
Sets the year y, month m and day d.
y must be in the range 1752-ca. 8000, m must be in the range 1-12, and d must be in the range 1-31. Exception: if y is in the range 0-99, it is interpreted as 1900-1999.
Returns TRUE if the date is valid, otherwise FALSE.
Definition at line 348 of file qdatetime.cpp.
QString QDate::toString | ( | ) | const |
Returns the date as a string.
The string format is "Sat May 20 1995". This function uses the dayName() and monthName() functions to generate the string.
Definition at line 324 of file qdatetime.cpp.
int QDate::year | ( | ) | const |
|
friend |
|
friend |
|
friend |
Definition at line 96 of file qdatetime.h.
|
private |
Definition at line 95 of file qdatetime.h.
|
staticprivate |
Definition at line 93 of file qdatetime.h.
|
staticprivate |
Definition at line 94 of file qdatetime.h.