<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/src/tools/qdatetime.cpp:198 --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>QDate Class</title> <style type="text/css"><!-- h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } body { background: #ffffff; color: black; } --></style> </head> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr bgcolor="#E5E5E5"> <td valign=center> <a href="index.html"> <font color="#004faf">Home</font></a> | <a href="classes.html"> <font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"> <font color="#004faf">Main Classes</font></a> | <a href="annotated.html"> <font color="#004faf">Annotated</font></a> | <a href="groups.html"> <font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"> <font color="#004faf">Functions</font></a> </td> <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QDate Class Reference</h1> <p>The QDate class provides date functions. <a href="#details">More...</a> <p><tt>#include <<a href="qdatetime-h.html">qdatetime.h</a>></tt> <p><a href="qdate-members.html">List of all member functions.</a> <h2>Public Members</h2> <ul> <li><div class=fn><a href="#QDate"><b>QDate</b></a> ()</div></li> <li><div class=fn><a href="#QDate-2"><b>QDate</b></a> ( int y, int m, int d )</div></li> <li><div class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</div></li> <li><div class=fn>bool <a href="#isValid"><b>isValid</b></a> () const</div></li> <li><div class=fn>int <a href="#year"><b>year</b></a> () const</div></li> <li><div class=fn>int <a href="#month"><b>month</b></a> () const</div></li> <li><div class=fn>int <a href="#day"><b>day</b></a> () const</div></li> <li><div class=fn>int <a href="#dayOfWeek"><b>dayOfWeek</b></a> () const</div></li> <li><div class=fn>int <a href="#dayOfYear"><b>dayOfYear</b></a> () const</div></li> <li><div class=fn>int <a href="#daysInMonth"><b>daysInMonth</b></a> () const</div></li> <li><div class=fn>int <a href="#daysInYear"><b>daysInYear</b></a> () const</div></li> <li><div class=fn>QString <a href="#toString-2"><b>toString</b></a> ( Qt::DateFormat f = Qt::TextDate ) const</div></li> <li><div class=fn>QString <a href="#toString"><b>toString</b></a> ( const QString & format ) const</div></li> <li><div class=fn>bool <a href="#setYMD"><b>setYMD</b></a> ( int y, int m, int d )</div></li> <li><div class=fn>QDate <a href="#addDays"><b>addDays</b></a> ( int ndays ) const</div></li> <li><div class=fn>QDate <a href="#addMonths"><b>addMonths</b></a> ( int nmonths ) const</div></li> <li><div class=fn>QDate <a href="#addYears"><b>addYears</b></a> ( int nyears ) const</div></li> <li><div class=fn>int <a href="#daysTo"><b>daysTo</b></a> ( const QDate & d ) const</div></li> <li><div class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const QDate & d ) const</div></li> <li><div class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const QDate & d ) const</div></li> <li><div class=fn>bool <a href="#operator-lt"><b>operator<</b></a> ( const QDate & d ) const</div></li> <li><div class=fn>bool <a href="#operator-lt-eq"><b>operator<=</b></a> ( const QDate & d ) const</div></li> <li><div class=fn>bool <a href="#operator-gt"><b>operator></b></a> ( const QDate & d ) const</div></li> <li><div class=fn>bool <a href="#operator-gt-eq"><b>operator>=</b></a> ( const QDate & d ) const</div></li> </ul> <h2>Static Public Members</h2> <ul> <li><div class=fn>QString monthName ( int month ) <em>(obsolete)</em></div></li> <li><div class=fn>QString dayName ( int weekday ) <em>(obsolete)</em></div></li> <li><div class=fn>QString <a href="#shortMonthName"><b>shortMonthName</b></a> ( int month )</div></li> <li><div class=fn>QString <a href="#shortDayName"><b>shortDayName</b></a> ( int weekday )</div></li> <li><div class=fn>QString <a href="#longMonthName"><b>longMonthName</b></a> ( int month )</div></li> <li><div class=fn>QString <a href="#longDayName"><b>longDayName</b></a> ( int weekday )</div></li> <li><div class=fn>QDate <a href="#currentDate"><b>currentDate</b></a> ()</div></li> <li><div class=fn>QDate <a href="#fromString"><b>fromString</b></a> ( const QString & s, Qt::DateFormat f = Qt::TextDate )</div></li> <li><div class=fn>bool <a href="#isValid-2"><b>isValid</b></a> ( int y, int m, int d )</div></li> <li><div class=fn>bool <a href="#leapYear"><b>leapYear</b></a> ( int y )</div></li> </ul> <h2>Related Functions</h2> <ul> <li><div class=fn>QDataStream & <a href="#operator-lt-lt"><b>operator<<</b></a> ( QDataStream & s, const QDate & d )</div></li> <li><div class=fn>QDataStream & <a href="#operator-gt-gt"><b>operator>></b></a> ( QDataStream & s, QDate & d )</div></li> </ul> <hr><a name="details"></a><h2>Detailed Description</h2> The QDate class provides date functions. <p> <p> 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 dates, e.g. by adding a number of days or months or years. <p> A QDate object is typically created either by giving the year, month and day numbers explicitly, or by using the static function <a href="#currentDate">currentDate</a>(), which makes a QDate object which contains the system clock's date. An explicit date can also be set using <a href="#setYMD">setYMD</a>(). The <a href="#fromString">fromString</a>() function returns a QDate given a string and a date format which is used to interpret the date within the string. <p> The <a href="#year">year</a>(), <a href="#month">month</a>(), and <a href="#day">day</a>() functions provide access to the year, month, and day numbers. Also, <a href="#dayOfWeek">dayOfWeek</a>() and <a href="#dayOfYear">dayOfYear</a>() functions are provided. The same information is provided in textual format by the <a href="#toString">toString</a>(), <a href="#shortDayName">shortDayName</a>(), <a href="#longDayName">longDayName</a>(), <a href="#shortMonthName">shortMonthName</a>() and <a href="#longMonthName">longMonthName</a>() functions. <p> QDate provides a full set of operators to compare two QDate objects where smaller means earlier and larger means later. <p> You can increment (or decrement) a date by a given number of days using <a href="#addDays">addDays</a>(). Similarly you can use <a href="#addMonths">addMonths</a>() and <a href="#addYears">addYears</a>(). The <a href="#daysTo">daysTo</a>() function returns the number of days between two dates. <p> The <a href="#daysInMonth">daysInMonth</a>() and <a href="#daysInYear">daysInYear</a>() functions return how many days there are in this date's month and year, respectively. The <a href="#leapYear">leapYear</a>() function indicates whether this date is in a leap year. <p> Note that QDate should not be used for date calculations for dates prior to the introduction of the Gregorian calendar. This calendar was adopted by England from 14<sup><small>th</small></sup> September 1752 (hence this is the earliest valid QDate), and subsequently by most other western countries, until 1923. <p> The end of time is reached around 8000, by which time we expect Qt to be obsolete. <p> <p>See also <a href="qtime.html">QTime</a>, <a href="qdatetime.html">QDateTime</a>, <a href="qdateedit.html">QDateEdit</a>, <a href="qdatetimeedit.html">QDateTimeEdit</a> and <a href="time.html">Time and Date</a>. <hr><h2>Member Function Documentation</h2> <h3 class=fn><a name="QDate"></a>QDate::QDate () </h3> Constructs a null date. Null dates are invalid. <p> <p>See also <a href="#isNull">isNull</a>() and <a href="#isValid">isValid</a>(). <h3 class=fn><a name="QDate-2"></a>QDate::QDate ( int y, int m, int d ) </h3> Constructs a date with year <em>y</em>, month <em>m</em> and day <em>d</em>. <p> <em>y</em> must be in the range 1752..8000, <em>m</em> must be in the range 1..12, and <em>d</em> must be in the range 1..31. Exception: if <em>y</em> is in the range 0..99, it is interpreted as 1900..1999. <p> <p>See also <a href="#isValid">isValid</a>(). <h3 class=fn><a href="qdate.html">QDate</a> <a name="addDays"></a>QDate::addDays ( int ndays ) const </h3> Returns a QDate object containing a date <em>ndays</em> later than the date of this object (or earlier if <em>ndays</em> is negative). <p> <p>See also <a href="#daysTo">daysTo</a>(). <h3 class=fn><a href="qdate.html">QDate</a> <a name="addMonths"></a>QDate::addMonths ( int nmonths ) const </h3> Returns a QDate object containing a date <em>nmonths</em> later than the date of this object (or earlier if <em>nmonths</em> is negative). <p> <h3 class=fn><a href="qdate.html">QDate</a> <a name="addYears"></a>QDate::addYears ( int nyears ) const </h3> Returns a QDate object containing a date <em>nyears</em> later than the date of this object (or earlier if <em>nyears</em> is negative). <p> <h3 class=fn><a href="qdate.html">QDate</a> <a name="currentDate"></a>QDate::currentDate ()<tt> [static]</tt> </h3> Returns the current date, as reported by the system clock. <p> <p>See also <a href="qtime.html#currentTime">QTime::currentTime</a>() and <a href="qdatetime.html#currentDateTime">QDateTime::currentDateTime</a>(). <p>Example: <a href="dclock-example.html#x1760">dclock/dclock.cpp</a>. <h3 class=fn>int <a name="day"></a>QDate::day () const </h3> Returns the day of the month (1..31) of this date. <p> <p>See also <a href="#year">year</a>(), <a href="#month">month</a>() and <a href="#dayOfWeek">dayOfWeek</a>(). <p>Example: <a href="dclock-example.html#x1761">dclock/dclock.cpp</a>. <h3 class=fn><a href="qstring.html">QString</a> <a name="dayName"></a>QDate::dayName ( int weekday )<tt> [static]</tt> </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> Use <a href="#shortDayName">shortDayName</a>() instead. <h3 class=fn>int <a name="dayOfWeek"></a>QDate::dayOfWeek () const </h3> Returns the weekday (Monday=1..Sunday=7) for this date. <p> <p>See also <a href="#day">day</a>() and <a href="#dayOfYear">dayOfYear</a>(). <h3 class=fn>int <a name="dayOfYear"></a>QDate::dayOfYear () const </h3> Returns the day of the year (1..365) for this date. <p> <p>See also <a href="#day">day</a>() and <a href="#dayOfWeek">dayOfWeek</a>(). <h3 class=fn>int <a name="daysInMonth"></a>QDate::daysInMonth () const </h3> Returns the number of days in the month (28..31) for this date. <p> <p>See also <a href="#day">day</a>() and <a href="#daysInYear">daysInYear</a>(). <h3 class=fn>int <a name="daysInYear"></a>QDate::daysInYear () const </h3> Returns the number of days in the year (365 or 366) for this date. <p> <p>See also <a href="#day">day</a>() and <a href="#daysInMonth">daysInMonth</a>(). <h3 class=fn>int <a name="daysTo"></a>QDate::daysTo ( const <a href="qdate.html">QDate</a> & d ) const </h3> Returns the number of days from this date to <em>d</em> (which is negative if <em>d</em> is earlier than this date). <p> Example: <pre> QDate d1( 1995, 5, 17 ); // May 17th 1995 QDate d2( 1995, 5, 20 ); // May 20th 1995 d1.<a href="#daysTo">daysTo</a>( d2 ); // returns 3 d2.<a href="#daysTo">daysTo</a>( d1 ); // returns -3 </pre> <p> <p>See also <a href="#addDays">addDays</a>(). <h3 class=fn><a href="qdate.html">QDate</a> <a name="fromString"></a>QDate::fromString ( const <a href="qstring.html">QString</a> & s, <a href="qt.html#DateFormat-enum">Qt::DateFormat</a> f = Qt::TextDate )<tt> [static]</tt> </h3> Returns the QDate represented by the string <em>s</em>, using the format <em>f</em>, or an invalid date if this is not possible. <p> Qt::LocalDate cannot be used here. <p> Note for Qt::TextDate: It is recommended to use the English short month names (e.g. Jan). Localized month names may also be used, but they depend on the user's locale settings. <h3 class=fn>bool <a name="isNull"></a>QDate::isNull () const </h3> <p> Returns TRUE if the date is null; otherwise returns FALSE. A null date is invalid. <p> <p>See also <a href="#isValid">isValid</a>(). <h3 class=fn>bool <a name="isValid"></a>QDate::isValid () const </h3> Returns TRUE if this date is valid; otherwise returns FALSE. <p> <p>See also <a href="#isNull">isNull</a>(). <h3 class=fn>bool <a name="isValid-2"></a>QDate::isValid ( int y, int m, int d )<tt> [static]</tt> </h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function. <p> Returns TRUE if the specified date (year <em>y</em>, month <em>m</em> and day <em>d</em>) is valid. <p> Example: <pre> QDate::<a href="#isValid">isValid</a>( 2002, 5, 17 ); // TRUE May 17th 2002 is valid QDate::<a href="#isValid">isValid</a>( 2002, 2, 30 ); // FALSE Feb 30th does not exist QDate::<a href="#isValid">isValid</a>( 2004, 2, 29 ); // TRUE 2004 is a leap year QDate::<a href="#isValid">isValid</a>( 1202, 6, 6 ); // FALSE 1202 is pre-Gregorian </pre> <p> Note that a <em>y</em> value in the range 00..99 is interpreted as 1900..1999. <p> <p>See also <a href="#isNull">isNull</a>() and <a href="#setYMD">setYMD</a>(). <h3 class=fn>bool <a name="leapYear"></a>QDate::leapYear ( int y )<tt> [static]</tt> </h3> Returns TRUE if the specified year <em>y</em> is a leap year. <h3 class=fn><a href="qstring.html">QString</a> <a name="longDayName"></a>QDate::longDayName ( int weekday )<tt> [static]</tt> </h3> Returns the long name of the <em>weekday</em>. <p> 1 = "Monday", 2 = "Tuesday", ... 7 = "Sunday" <p> The day names will be localized according to the system's locale settings. <p> <p>See also <a href="#toString">toString</a>(), <a href="#shortDayName">shortDayName</a>(), <a href="#shortMonthName">shortMonthName</a>() and <a href="#longMonthName">longMonthName</a>(). <h3 class=fn><a href="qstring.html">QString</a> <a name="longMonthName"></a>QDate::longMonthName ( int month )<tt> [static]</tt> </h3> Returns the long name of the <em>month</em>. <p> 1 = "January", 2 = "February", ... 12 = "December" <p> The month names will be localized according to the system's locale settings. <p> <p>See also <a href="#toString">toString</a>(), <a href="#shortMonthName">shortMonthName</a>(), <a href="#shortDayName">shortDayName</a>() and <a href="#longDayName">longDayName</a>(). <h3 class=fn>int <a name="month"></a>QDate::month () const </h3> Returns the month (January=1..December=12) of this date. <p> <p>See also <a href="#year">year</a>() and <a href="#day">day</a>(). <p>Example: <a href="dclock-example.html#x1762">dclock/dclock.cpp</a>. <h3 class=fn><a href="qstring.html">QString</a> <a name="monthName"></a>QDate::monthName ( int month )<tt> [static]</tt> </h3> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code. <p> Use <a href="#shortMonthName">shortMonthName</a>() instead. <h3 class=fn>bool <a name="operator!-eq"></a>QDate::operator!= ( const <a href="qdate.html">QDate</a> & d ) const </h3> Returns TRUE if this date is different from <em>d</em>; otherwise returns FALSE. <h3 class=fn>bool <a name="operator-lt"></a>QDate::operator< ( const <a href="qdate.html">QDate</a> & d ) const </h3> Returns TRUE if this date is earlier than <em>d</em>, otherwise returns FALSE. <h3 class=fn>bool <a name="operator-lt-eq"></a>QDate::operator<= ( const <a href="qdate.html">QDate</a> & d ) const </h3> Returns TRUE if this date is earlier than or equal to <em>d</em>, otherwise returns FALSE. <h3 class=fn>bool <a name="operator-eq-eq"></a>QDate::operator== ( const <a href="qdate.html">QDate</a> & d ) const </h3> Returns TRUE if this date is equal to <em>d</em>; otherwise returns FALSE. <h3 class=fn>bool <a name="operator-gt"></a>QDate::operator> ( const <a href="qdate.html">QDate</a> & d ) const </h3> Returns TRUE if this date is later than <em>d</em>, otherwise returns FALSE. <h3 class=fn>bool <a name="operator-gt-eq"></a>QDate::operator>= ( const <a href="qdate.html">QDate</a> & d ) const </h3> Returns TRUE if this date is later than or equal to <em>d</em>, otherwise returns FALSE. <h3 class=fn>bool <a name="setYMD"></a>QDate::setYMD ( int y, int m, int d ) </h3> Sets the date's year <em>y</em>, month <em>m</em> and day <em>d</em>. <p> <em>y</em> must be in the range 1752..8000, <em>m</em> must be in the range 1..12, and <em>d</em> must be in the range 1..31. Exception: if <em>y</em> is in the range 0..99, it is interpreted as 1900..1999. <p> Returns TRUE if the date is valid, otherwise returns FALSE. <h3 class=fn><a href="qstring.html">QString</a> <a name="shortDayName"></a>QDate::shortDayName ( int weekday )<tt> [static]</tt> </h3> Returns the name of the <em>weekday</em>. <p> 1 = "Mon", 2 = "Tue", ... 7 = "Sun" <p> The day names will be localized according to the system's locale settings. <p> <p>See also <a href="#toString">toString</a>(), <a href="#shortMonthName">shortMonthName</a>(), <a href="#longMonthName">longMonthName</a>() and <a href="#longDayName">longDayName</a>(). <h3 class=fn><a href="qstring.html">QString</a> <a name="shortMonthName"></a>QDate::shortMonthName ( int month )<tt> [static]</tt> </h3> Returns the name of the <em>month</em>. <p> 1 = "Jan", 2 = "Feb", ... 12 = "Dec" <p> The month names will be localized according to the system's locale settings. <p> <p>See also <a href="#toString">toString</a>(), <a href="#longMonthName">longMonthName</a>(), <a href="#shortDayName">shortDayName</a>() and <a href="#longDayName">longDayName</a>(). <h3 class=fn><a href="qstring.html">QString</a> <a name="toString"></a>QDate::toString ( const <a href="qstring.html">QString</a> & format ) const </h3> Returns the datetime as a string. The <em>format</em> parameter determines the format of the result string. <p> These expressions may be used: <p> <ul> <li> <em>d</em> - the day as number without a leading zero (1-31) <li> <em>dd</em> - the day as number with a leading zero (01-31) <li> <em>ddd</em> - the abbrevated day name (Mon - Sun). Uses <a href="#shortDayName">QDate::shortDayName</a>(). <li> <em>dddd</em> - the long day name (Monday - Sunday). Uses <a href="#longDayName">QDate::longDayName</a>(). <li> <em>M</em> - the month as number without a leading zero (1-12) <li> <em>MM</em> - the month as number with a leading zero (01-12) <li> <em>MMM</em> - the abbrevated month name (Jan - Dec). Uses <a href="#shortMonthName">QDate::shortMonthName</a>(). <li> <em>MMMM</em> - the long month name (January - December). Uses <a href="#longMonthName">QDate::longMonthName</a>(). <li> <em>yy</em> - the year as two digit number (00-99) <li> <em>yyyy</em> - the year as four digit number (0000-9999) </ul> <p> All other input characters will be ignored. <p> Example format Strings (assumed that the QDate is 21. May 2001) <p> <ul> <li> "dd.MM.yyyy" will result in "21.05.2001" <li> "ddd MMMM d yy" will result in "Tue May 21 01" </ul> <p> <p>See also <a href="#toString">QDate::toString</a>() and <a href="qtime.html#toString">QTime::toString</a>(). <p> <h3 class=fn><a href="qstring.html">QString</a> <a name="toString-2"></a>QDate::toString ( <a href="qt.html#DateFormat-enum">Qt::DateFormat</a> f = Qt::TextDate ) const </h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function. <p> Returns the date as a string. The <em>f</em> parameter determines the format of the string. <p> If <em>f</em> is Qt::TextDate, the string format is "Sat May 20 1995" (using the <a href="#shortDayName">shortDayName</a>() and <a href="#shortMonthName">shortMonthName</a>() functions to generate the string). <p> If <em>f</em> is Qt::ISODate, the string format corresponds to the ISO 8601 specification for representations of dates, which is YYYY-MM-DD where YYYY is the year, MM is the month of the year (between 01 and 12), and DD is the day of the month between 01 and 31. <p> If <em>f</em> is Qt::LocalDate, the string format depends on the locale settings of the system. <p> <p>See also <a href="#shortDayName">shortDayName</a>() and <a href="#shortMonthName">shortMonthName</a>(). <h3 class=fn>int <a name="year"></a>QDate::year () const </h3> Returns the year (1752..8000) of this date. <p> <p>See also <a href="#month">month</a>() and <a href="#day">day</a>(). <hr><h2>Related Functions</h2> <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt"></a>operator<< ( <a href="qdatastream.html">QDataStream</a> & s, const <a href="qdate.html">QDate</a> & d ) </h3> Writes the date, <em>d</em>, to the data stream, <em>s</em>. <p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>. <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt"></a>operator>> ( <a href="qdatastream.html">QDataStream</a> & s, <a href="qdate.html">QDate</a> & d ) </h3> Reads a date from the stream <em>s</em> into <em>d</em>. <p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>. <!-- eof --> <hr><p> This file is part of the <a href="index.html">Qt toolkit</a>. Copyright © 1995-2001 <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center> <table width=100% cellspacing=0 border=0><tr> <td>Copyright © 2001 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a> <td align=right><div align=right>Qt version 3.0.2</div> </table></div></address></body> </html>