ISLEman
Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Friends | List of all members
QDate Class Reference

The QDate class provides date functions. More...

#include <qdatetime.h>

Public Member Functions

 QDate ()
 
 QDate (int y, int m, int d)
 
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)
 

Friends

class QDateTime
 
Q_EXPORT QDataStreamoperator<< (QDataStream &, const QDate &)
 
Q_EXPORT QDataStreamoperator>> (QDataStream &, QDate &)
 

Detailed Description

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.

See also
QTime, QDateTime

Constructor & Destructor Documentation

§ QDate() [1/2]

QDate::QDate ( )
inline

Constructs a null date. Null dates are invalid.

See also
isNull(), isValid()

§ QDate() [2/2]

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.

See also
isValid()

Member Function Documentation

§ addDays()

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).

See also
daysTo()

§ currentDate()

QDate QDate::currentDate ( )
static

Returns the current date, as reported by the system clock.

See also
QTime::currentTime(), QDateTime::currentDateTime()

§ day()

int QDate::day ( ) const

Returns the day of the month (1..31) of this date.

See also
year(), month(), dayOfWeek()

§ dayName()

QString QDate::dayName ( int  weekday) const
virtual

Returns the name of the weekday.

Weekday 1 == "Mon", day 2 == "Tue" etc.

See also
toString(), monthName()

§ dayOfWeek()

int QDate::dayOfWeek ( ) const

Returns the weekday (Monday=1 .. Sunday=7) for this date.

See also
day(), dayOfYear()

§ dayOfYear()

int QDate::dayOfYear ( ) const

Returns the day of the year (1..365) for this date.

See also
day(), dayOfWeek()

§ daysInMonth()

int QDate::daysInMonth ( ) const

Returns the number of days in the month (28..31) for this date.

See also
day(), daysInYear()

§ daysInYear()

int QDate::daysInYear ( ) const

Returns the number of days in the year (365 or 366) for this date.

See also
day(), daysInMonth()

§ daysTo()

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).

Example:

QDate d1( 1995, 5, 17 ); // May 17th 1995
QDate d2( 1995, 5, 20 ); // May 20th 1995
d1.daysTo( d2 ); // returns 3
d2.daysTo( d1 ); // returns -3
See also
addDays()

§ isNull()

bool QDate::isNull ( ) const
inline

Returns TRUE if the date is null. A null date is invalid.

See also
isValid()

§ isValid() [1/2]

bool QDate::isValid ( ) const

Returns TRUE if this date is valid.

See also
isNull()

§ isValid() [2/2]

bool QDate::isValid ( int  y,
int  m,
int  d 
)
static

Returns TRUE if the specified date (year y, month m and day d) is valid.

Example:

QDate::isValid( 2002, 5, 17 ); // TRUE; May 17th 2002 is OK.
QDate::isValid( 2002, 2, 30 ); // FALSE; Feb 30th does not exist
QDate::isValid( 2004, 2, 29 ); // TRUE; 2004 is a leap year
QDate::isValid( 1202, 6, 6 ); // FALSE; 1202 is pre-Gregorian

Note that a y value in the range 00-99 is interpreted as 1900-1999.

See also
isNull(), setYMD()

§ leapYear()

bool QDate::leapYear ( int  y)
static

Returns TRUE if the specified year y is a leap year.

§ month()

int QDate::month ( ) const

Returns the month (January=1 .. December=12) of this date.

See also
year(), day()

§ monthName()

QString QDate::monthName ( int  month) const
virtual

Returns the name of the month.

Month 1 == "Jan", month 2 == "Feb" etc.

See also
toString(), dayName()

§ operator!=()

bool QDate::operator!= ( const QDate d) const
inline

Returns TRUE if this date is different from d, or FALSE if they are equal.

§ operator<()

bool QDate::operator< ( const QDate d) const
inline

Returns TRUE if this date is earlier than d, otherwise FALSE.

§ operator<=()

bool QDate::operator<= ( const QDate d) const
inline

Returns TRUE if this date is earlier than or equal to d, otherwise FALSE.

§ operator==()

bool QDate::operator== ( const QDate d) const
inline

Returns TRUE if this date is equal to d, or FALSE if they are different.

§ operator>()

bool QDate::operator> ( const QDate d) const
inline

Returns TRUE if this date is later than d, otherwise FALSE.

§ operator>=()

bool QDate::operator>= ( const QDate d) const
inline

Returns TRUE if this date is later than or equal to d, otherwise FALSE.

§ setYMD()

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.

§ toString()

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.

See also
dayName(), monthName()

§ year()

int QDate::year ( ) const

Returns the year (>= 1752) of this date.

See also
month(), day()

Friends And Related Function Documentation

§ operator<<

QDataStream & operator<< ( QDataStream s,
const QDate d 
)
friend

Writes the date to the stream.

See also
Format of the QDataStream operators

§ operator>>

QDataStream & operator>> ( QDataStream s,
QDate d 
)
friend

Reads a date from the stream.

See also
Format of the QDataStream operators

The documentation for this class was generated from the following files: