Qt 4.8
|
The QDate class provides date functions. More...
#include <qdatetime.h>
Public Types | |
enum | MonthNameType { DateFormat = 0, StandaloneFormat } |
This enum describes the types of the string representation used for the month name. More... | |
Public Functions | |
QDate | addDays (int days) const |
Returns a QDate object containing a date ndays later than the date of this object (or earlier if ndays is negative). More... | |
QDate | addMonths (int months) const |
Returns a QDate object containing a date nmonths later than the date of this object (or earlier if nmonths is negative). More... | |
QDate | addYears (int years) const |
Returns a QDate object containing a date nyears later than the date of this object (or earlier if nyears is negative). More... | |
int | day () const |
Returns the day of the month (1 to 31) of this date. More... | |
int | dayOfWeek () const |
Returns the weekday (1 = Monday to 7 = Sunday) for this date. More... | |
int | dayOfYear () const |
Returns the day of the year (1 to 365 or 366 on leap years) for this date. More... | |
int | daysInMonth () const |
Returns the number of days in the month (28 to 31) for this date. More... | |
int | daysInYear () const |
Returns the number of days in the year (365 or 366) for this date. More... | |
int | daysTo (const QDate &) const |
Returns the number of days from this date to d (which is negative if d is earlier than this date). More... | |
void | getDate (int *year, int *month, int *day) |
bool | isNull () const |
Returns true if the date is null; otherwise returns false. More... | |
bool | isValid () const |
Returns true if this date is valid; otherwise returns false. More... | |
int | month () const |
Returns the number corresponding to the month of this date, using the following convention: More... | |
bool | operator!= (const QDate &other) const |
Returns true if this date is different from d; otherwise returns false. More... | |
bool | operator< (const QDate &other) const |
Returns true if this date is earlier than d; otherwise returns false. More... | |
bool | operator<= (const QDate &other) const |
Returns true if this date is earlier than or equal to d; otherwise returns false. More... | |
bool | operator== (const QDate &other) const |
Returns true if this date is equal to d; otherwise returns false. More... | |
bool | operator> (const QDate &other) const |
Returns true if this date is later than d; otherwise returns false. More... | |
bool | operator>= (const QDate &other) const |
Returns true if this date is later than or equal to d; otherwise returns false. More... | |
QDate () | |
Constructs a null date. More... | |
QDate (int y, int m, int d) | |
Constructs a date with year y, month m and day d. More... | |
bool | setDate (int year, int month, int day) |
Sets the date's year, month, and day. More... | |
bool | setYMD (int y, int m, int d) |
Sets the date's year y, month m, and day d. More... | |
int | toJulianDay () const |
Converts the date to a Julian day. More... | |
QString | toString (Qt::DateFormat f=Qt::TextDate) const |
Returns the date as a string. More... | |
QString | toString (const QString &format) const |
Returns the date as a string. More... | |
int | weekNumber (int *yearNum=0) const |
Returns the week number (1 to 53), and stores the year in {yearNumber} unless yearNumber is null (the default). More... | |
int | year () const |
Returns the year of this date. More... | |
Static Public Functions | |
static QDate | currentDate () |
Returns the current date, as reported by the system clock. More... | |
static QDate | fromJulianDay (int jd) |
Converts the Julian day jd to a QDate. More... | |
static QDate | fromString (const QString &s, Qt::DateFormat f=Qt::TextDate) |
Returns the QDate represented by the string, using the format given, or an invalid date if the string cannot be parsed. More... | |
static QDate | fromString (const QString &s, const QString &format) |
Returns the QDate represented by the string, using the format given, or an invalid date if the string cannot be parsed. More... | |
static uint | gregorianToJulian (int y, int m, int d) |
This function has a confusing name and shouldn't be part of the API anyway, since we have toJulian() and fromJulian(). More... | |
static bool | isLeapYear (int year) |
Returns true if the specified year is a leap year; otherwise returns false. More... | |
static bool | isValid (int y, int m, int d) |
Returns true if the specified date (year, month, and day) is valid; otherwise returns false. More... | |
static void | julianToGregorian (uint jd, int &y, int &m, int &d) |
This function has a confusing name and shouldn't be part of the API anyway, since we have toJulian() and fromJulian(). More... | |
static QString | longDayName (int weekday) |
Returns the long version of the name of the weekday. More... | |
static QString | longDayName (int weekday, MonthNameType type) |
Returns the long name of the weekday for the representation specified by type. More... | |
static QString | longMonthName (int month) |
Returns the long version of the name of the month. More... | |
static QString | longMonthName (int month, MonthNameType type) |
Returns the long name of the month for the representation specified by type. More... | |
static QString | shortDayName (int weekday) |
Returns the short version of the name of the weekday. More... | |
static QString | shortDayName (int weekday, MonthNameType type) |
Returns the short name of the weekday for the representation specified by type. More... | |
static QString | shortMonthName (int month) |
Returns the short version of the name of the month. More... | |
static QString | shortMonthName (int month, MonthNameType type) |
Returns the short name of the month for the representation specified by type. More... | |
Properties | |
uint | jd |
Friends | |
Q_CORE_EXPORT QDataStream & | operator<< (QDataStream &, const QDate &) |
Writes the date to stream out. More... | |
Q_CORE_EXPORT QDataStream & | operator>> (QDataStream &, QDate &) |
Reads a date from stream in into the date. More... | |
class | QDateTime |
class | QDateTimePrivate |
The QDate class provides date functions.
A QDate object contains a calendar date, i.e. year, month, and day numbers, in the Gregorian calendar. (see QDate G and J {Use of Gregorian and Julian Calendars} for dates prior to 15 October 1582). 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 either 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.
Definition at line 55 of file qdatetime.h.
enum QDate::MonthNameType |
This enum describes the types of the string representation used for the month name.
Enumerator | |
---|---|
DateFormat | |
StandaloneFormat |
Definition at line 58 of file qdatetime.h.
|
inline |
Constructs a null date.
Null dates are invalid.
Definition at line 63 of file qdatetime.h.
Referenced by addMonths(), addYears(), and fromString().
QDate::QDate | ( | int | y, |
int | m, | ||
int | d | ||
) |
Constructs a date with year y, month m and day d.
If the specified date is invalid, the date is not set and isValid() returns false. A date before 2 January 4713 B.C. is considered invalid.
Definition at line 313 of file qdatetime.cpp.
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 989 of file qdatetime.cpp.
Referenced by QDateTime::addDays(), QPatternist::AbstractDateTime::create(), QCalendarModel::dateForCell(), fromDate(), fromTimeStamp(), QTDSResult::gotoNext(), QCalendarView::moveCursor(), QDateTime::setMSecsSinceEpoch(), and QDateTime::setTime_t().
QDate QDate::addMonths | ( | int | nmonths | ) | const |
Returns a QDate object containing a date nmonths later than the date of this object (or earlier if nmonths is negative).
Definition at line 1016 of file qdatetime.cpp.
Referenced by QCalendarWidgetPrivate::_q_monthChanged(), QCalendarWidgetPrivate::_q_nextMonthClicked(), QCalendarWidgetPrivate::_q_prevMonthClicked(), QDateTime::addMonths(), QCalendarView::moveCursor(), and QCalendarView::wheelEvent().
QDate QDate::addYears | ( | int | nyears | ) | const |
Returns a QDate object containing a date nyears later than the date of this object (or earlier if nyears is negative).
Definition at line 1081 of file qdatetime.cpp.
Referenced by QCalendarWidgetPrivate::_q_yearEditingFinished(), and QDateTime::addYears().
|
static |
Returns the current date, as reported by the system clock.
If spec is Qt::LocalTime, use the currentDate() overload that takes no parameters instead; otherwise, use QDateTime::currentDateTime().
QDate localDate = QDate::currentDate(Qt::LocalTime); QDate utcDate = QDate::currentDate(Qt::UTC); QDate localDate = QDate::currentDate(); QDate utcDate = QDateTime::currentDateTime().toUTC().date();
Definition at line 3115 of file qdatetime.cpp.
Referenced by _q_parseUnixDir(), QCalendarTextNavigator::applyDate(), QDateTime::currentMSecsSinceEpoch(), macTimeToString(), QCalendarDateValidator::QCalendarDateValidator(), QCalendarModel::QCalendarModel(), qEncodeNtlmv2Response(), qt_eval_days_left(), and QCalendarWidget::showToday().
int QDate::day | ( | ) | const |
Returns the day of the month (1 to 31) of this date.
Definition at line 395 of file qdatetime.cpp.
Referenced by _q_fixupDateTime(), _q_parseDosDir(), _q_parseUnixDir(), adjustDate(), QCalendarMonthValidator::applyToDate(), QCalendarYearValidator::applyToDate(), QCalendarModel::cellForDate(), QCalendarModel::columnForFirstOfMonth(), QCalendarModel::data(), QCalendarModel::dateForCell(), QScript::DateTimeToMs(), QLocalePrivate::dateTimeToString(), QDB2Result::exec(), QODBCResult::exec(), QPatternist::DayFromAbstractDateTimeFN::extract(), QDB2Driver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QODBCDriver::formatValue(), QPSQLDriver::formatValue(), QPatternist::GMonthDay::fromDateTime(), QPatternist::GDay::fromDateTime(), fromString(), QDateTimeParser::getDigit(), localToUtc(), macDateToString(), macTimeToString(), operator<<(), QDateTimeToDATE(), qMakeOraDate(), QCalendarWidget::setCurrentPage(), QCalendarDayValidator::setDate(), QDateTimeParser::setDigit(), QDateTimeEditPrivate::stepBy(), QCalendarDayValidator::text(), toString(), QSystemLocalePrivate::toString(), QDateTime::toString(), QMYSQLResult::virtual_hook(), QPdfEnginePrivate::writeInfo(), and writeMSDosDate().
int QDate::dayOfWeek | ( | ) | const |
Returns the weekday (1 = Monday to 7 = Sunday) for this date.
Definition at line 408 of file qdatetime.cpp.
Referenced by QCalendarModel::columnForFirstOfMonth(), QScript::DateTimeToMs(), QLocalePrivate::dateTimeToString(), QDateTimeParser::parse(), QCalendarDayValidator::text(), toString(), QDateTime::toString(), and weekNumber().
int QDate::dayOfYear | ( | ) | const |
Returns the day of the year (1 to 365 or 366 on leap years) for this date.
Definition at line 420 of file qdatetime.cpp.
Referenced by QScript::DateTimeToMs(), and weekNumber().
int QDate::daysInMonth | ( | ) | const |
Returns the number of days in the month (28 to 31) for this date.
Definition at line 431 of file qdatetime.cpp.
Referenced by QDateTimeParser::absoluteMax(), QCalendarDayValidator::applyToDate(), fixedDate(), QCalendarView::moveCursor(), QDateTimeParser::parse(), QCalendarWidget::setCurrentPage(), QDateTimeParser::setDigit(), and QDateTimeEditPrivate::stepBy().
int QDate::daysInYear | ( | ) | const |
Returns the number of days in the year (365 or 366) for this date.
Definition at line 447 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).
Example:
Definition at line 1111 of file qdatetime.cpp.
Referenced by QCalendarModel::cellForDate(), QDateTime::daysTo(), localToUtc(), QDateTime::msecsTo(), qt_eval_days_left(), QDateTime::secsTo(), toDate(), toTimeStamp(), QCalendarWidgetPrivate::updateCurrentPage(), and utcToLocal().
|
inlinestatic |
Converts the Julian day jd to a QDate.
Definition at line 133 of file qdatetime.h.
Referenced by QCalendarModel::QCalendarModel().
|
static |
Returns the QDate represented by the string, using the format given, or an invalid date if the string cannot be parsed.
Note for Qt::TextDate: It is recommended that you use the English short month names (e.g. "Jan"). Although localized month names can also be used, they depend on the user's locale settings.
Definition at line 1203 of file qdatetime.cpp.
Referenced by QLibraryInfo::buildDate(), convert(), QPSQLResult::data(), QDeclarativeStringConverters::dateFromString(), QTime::fromString(), QDateTime::fromString(), QTDSResult::gotoNext(), and qDateFromString().
Returns the QDate represented by the string, using the format given, or an invalid date if the string cannot be parsed.
These expressions may be used for the format:
Expression | Output |
d | The day as a number without a leading zero (1 to 31) |
dd | The day as a number with a leading zero (01 to 31) |
ddd | The abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName(). |
dddd | The long localized day name (e.g. 'Monday' to 'Sunday'). Uses QDate::longDayName(). |
M | The month as a number without a leading zero (1 to 12) |
MM | The month as a number with a leading zero (01 to 12) |
MMM | The abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName(). |
MMMM | The long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName(). |
yy | The year as two digit number (00 to 99) |
yyyy | The year as four digit number. If the year is negative, a minus sign is prepended in addition. |
All other input characters will be treated as text. Any sequence of characters that are enclosed in single quotes will also be treated as text and will not be used as an expression. For example:
If the format is not satisfied, an invalid QDate is returned. The expressions that don't expect leading zeroes (d, M) will be greedy. This means that they will use two digits even if this will put them outside the accepted range of values and leaves too few digits for other sections. For example, the following format string could have meant January 30 but the M will grab two digits, resulting in an invalid date:
For any field that is not represented in the format the following defaults are used:
Field | Default value |
Year | 1900 |
Month | 1 |
Day | 1 |
The following examples demonstrate the default values:
Definition at line 1347 of file qdatetime.cpp.
void QDate::getDate | ( | int * | year, |
int * | month, | ||
int * | day | ||
) |
Extracts the date's year, month, and day, and assigns them to year, *month, and *day. The pointers may be null.
Definition at line 977 of file qdatetime.cpp.
|
static |
This function has a confusing name and shouldn't be part of the API anyway, since we have toJulian() and fromJulian().
Definition at line 1426 of file qdatetime.cpp.
|
static |
Returns true if the specified year is a leap year; otherwise returns false.
Definition at line 1404 of file qdatetime.cpp.
Referenced by _q_fixupDateTime(), _q_parseUnixDir(), daysInMonth(), daysInYear(), isValid(), and weekNumber().
|
inline |
Returns true if the date is null; otherwise returns false.
A null date is invalid.
Definition at line 66 of file qdatetime.h.
Referenced by QDateTime::isNull(), isValid(), QDateTimeToDATE(), and QCalendarWidget::setDateTextFormat().
bool QDate::isValid | ( | ) | const |
Returns true if this date is valid; otherwise returns false.
Definition at line 340 of file qdatetime.cpp.
Referenced by addMonths(), addYears(), QCalendarModel::cellForDate(), convert(), QPatternist::AbstractDateTime::create(), QCalendarModel::data(), QCalendarModel::dateForCell(), QDeclarativeStringConverters::dateFromString(), QLocalePrivate::dateTimeToString(), QDateTimeEditPrivate::emitSignals(), QCalendarModel::flags(), fmtDateTime(), QSqlDriver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QDateTimeParser::fromString(), QCalendarView::handleMouseEvent(), QPatternist::AbstractDateTime::isRangeValid(), QDateTime::isValid(), localToUtc(), QCalendarView::mouseMoveEvent(), QCalendarView::mousePressEvent(), QCalendarView::mouseReleaseEvent(), operator<<(), QCalendarDelegate::paint(), QDateTimeParser::parse(), parseDateString(), QDateTime::QDateTime(), QDateTimeEdit::QDateTimeEdit(), QDateTimeToDATE(), QCalendarModel::referenceDate(), setDate(), QDateTimeEdit::setDate(), QDateTime::setDate(), QDateTimeEdit::setDateRange(), QCalendarWidget::setDateRange(), QDateTimeParser::setDigit(), QTime::setHMS(), QCalendarWidget::setMaximumDate(), QDateTimeEdit::setMaximumDate(), QCalendarModel::setMaximumDate(), QCalendarWidget::setMinimumDate(), QDateTimeEdit::setMinimumDate(), QCalendarModel::setMinimumDate(), QCalendarWidget::setSelectedDate(), toString(), QTest::toString(), QTime::toString(), QLocale::toString(), QCalendarWidget::updateCell(), QCalendarWidgetPrivate::updateCurrentPage(), and weekNumber().
|
static |
Returns true if the specified date (year, month, and day) is valid; otherwise returns false.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Example:
Definition at line 1377 of file qdatetime.cpp.
|
static |
This function has a confusing name and shouldn't be part of the API anyway, since we have toJulian() and fromJulian().
Definition at line 1441 of file qdatetime.cpp.
|
static |
Returns the long version of the name of the weekday.
The returned name is in normal type which can be used for date formatting.
Definition at line 767 of file qdatetime.cpp.
|
static |
Returns the long name of the weekday for the representation specified by type.
The days are enumerated using the following convention:
The day names will be localized according to the system's default locale settings.
Definition at line 744 of file qdatetime.cpp.
|
static |
Returns the long version of the name of the month.
The returned name is in normal type which can be used for date formatting.
Definition at line 651 of file qdatetime.cpp.
|
static |
Returns the long name of the month for the representation specified by type.
The months are enumerated using the following convention:
The month names will be localized according to the system's default locale settings.
Definition at line 628 of file qdatetime.cpp.
int QDate::month | ( | ) | const |
Returns the number corresponding to the month of this date, using the following convention:
Definition at line 382 of file qdatetime.cpp.
Referenced by _q_fixupDateTime(), QCalendarWidgetPrivate::_q_monthChanged(), _q_parseDosDir(), _q_parseUnixDir(), QCalendarWidgetPrivate::_q_slotChangeDate(), adjustDate(), QCalendarDayValidator::applyToDate(), QCalendarYearValidator::applyToDate(), QCalendarWidgetPrivate::createNavigationBar(), QScript::DateTimeToMs(), QLocalePrivate::dateTimeToString(), QDB2Result::exec(), QODBCResult::exec(), QPatternist::MonthFromAbstractDateTimeFN::extract(), QCalendarModel::formatForCell(), QDB2Driver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QODBCDriver::formatValue(), QPSQLDriver::formatValue(), QPatternist::GMonthDay::fromDateTime(), QPatternist::GYearMonth::fromDateTime(), QPatternist::GMonth::fromDateTime(), fromString(), QDateTimeParser::getDigit(), isValid(), localToUtc(), macDateToString(), macTimeToString(), QCalendarView::moveCursor(), operator<<(), QDateTimeParser::parse(), QDateTimeParser::parseSection(), QCalendarModel::QCalendarModel(), QDateTimeToDATE(), qMakeOraDate(), QCalendarMonthValidator::setDate(), QCalendarWidget::setDateRange(), QDateTimeParser::setDigit(), QCalendarWidget::setMaximumDate(), QCalendarWidget::setMinimumDate(), QCalendarWidget::setSelectedDate(), QCalendarWidget::showSelectedDate(), QCalendarWidget::showToday(), QCalendarMonthValidator::text(), toString(), QSystemLocalePrivate::toString(), QDateTime::toString(), QCalendarWidgetPrivate::updateCurrentPage(), QCalendarWidgetPrivate::updateMonthMenu(), QMYSQLResult::virtual_hook(), QPdfEnginePrivate::writeInfo(), and writeMSDosDate().
|
inline |
Returns true if this date is different from d; otherwise returns false.
Definition at line 108 of file qdatetime.h.
|
inline |
Returns true if this date is earlier than d; otherwise returns false.
Definition at line 109 of file qdatetime.h.
|
inline |
Returns true if this date is earlier than or equal to d; otherwise returns false.
Definition at line 110 of file qdatetime.h.
|
inline |
Returns true if this date is equal to d; otherwise returns false.
Definition at line 107 of file qdatetime.h.
|
inline |
Returns true if this date is later than d; otherwise returns false.
Definition at line 111 of file qdatetime.h.
|
inline |
Returns true if this date is later than or equal to d; otherwise returns false.
Definition at line 112 of file qdatetime.h.
bool QDate::setDate | ( | int | year, |
int | month, | ||
int | day | ||
) |
Sets the date's year, month, and day.
Returns true if the date is valid; otherwise returns false.
If the specified date is invalid, the QDate object is set to be invalid. Any date before 2 January 4713 B.C. is considered invalid.
Definition at line 959 of file qdatetime.cpp.
Referenced by adjustDate(), fixedDate(), QDate(), and setYMD().
bool QDate::setYMD | ( | int | y, |
int | m, | ||
int | d | ||
) |
Sets the date's year y, month m, and day d.
If y is in the range 0 to 99, it is interpreted as 1900 to 1999.
Use setDate() instead.
Definition at line 937 of file qdatetime.cpp.
Referenced by _q_fixupDateTime(), and operator>>().
|
static |
Returns the short version of the name of the weekday.
The returned name is in normal type which can be used for date formatting.
Definition at line 709 of file qdatetime.cpp.
Referenced by toString(), and QDateTime::toString().
|
static |
Returns the short name of the weekday for the representation specified by type.
The days are enumerated using the following convention:
The day names will be localized according to the system's default locale settings.
Definition at line 686 of file qdatetime.cpp.
|
static |
Returns the short version of the name of the month.
The returned name is in normal type which can be used for date formatting.
Definition at line 591 of file qdatetime.cpp.
Referenced by fromShortMonthName(), fromString(), toString(), and QDateTime::toString().
|
static |
Returns the short name of the month for the representation specified by type.
The months are enumerated using the following convention:
The month names will be localized according to the system's default locale settings.
Definition at line 568 of file qdatetime.cpp.
|
inline |
Converts the date to a Julian day.
Definition at line 134 of file qdatetime.h.
Referenced by QDeclarativeCompiler::genLiteralAssignment(), localToUtc(), QDateTimeParser::parse(), and utcToLocal().
QString QDate::toString | ( | Qt::DateFormat | format = Qt::TextDate | ) | const |
Returns the date as a string.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
The format parameter determines the format of the string.
If the format is Qt::TextDate, the string is formatted in the default way. QDate::shortDayName() and QDate::shortMonthName() are used to generate the string, so the day and month names will be localized names using the default locale from the system. An example of this formatting is "Sat May 20 1995".
If the format is Qt::ISODate, the string format corresponds to the ISO 8601 extended specification for representations of dates and times, taking the form 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.
If the format is Qt::SystemLocaleShortDate or Qt::SystemLocaleLongDate, the string format depends on the locale settings of the system. Identical to calling QLocale::system().toString(date, QLocale::ShortFormat) or QLocale::system().toString(date, QLocale::LongFormat).
If the format is Qt::DefaultLocaleShortDate or Qt::DefaultLocaleLongDate, the string format depends on the default application locale. This is the locale set with QLocale::setDefault(), or the system locale if no default locale has been set. Identical to calling QLocale().toString(date, QLocale::ShortFormat) or QLocale().toString(date, QLocale::LongFormat).
If the date is invalid, an empty string will be returned.
Definition at line 823 of file qdatetime.cpp.
Referenced by QDeclarativeEnginePrivate::formatDate(), QSqlDriver::formatValue(), operator<<(), QTest::toString(), and QDateTime::toString().
Returns the date as a string.
The format parameter determines the format of the result string.
These expressions may be used:
Expression | Output |
d | the day as number without a leading zero (1 to 31) |
dd | the day as number with a leading zero (01 to 31) |
ddd | the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName(). |
dddd | the long localized day name (e.g. 'Monday' to 'Sunday'). Uses QDate::longDayName(). |
M | the month as number without a leading zero (1 to 12) |
MM | the month as number with a leading zero (01 to 12) |
MMM | the abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName(). |
MMMM | the long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName(). |
yy | the year as two digit number (00 to 99) |
yyyy | the year as four digit number. If the year is negative, a minus sign is prepended in addition. |
All other input characters will be ignored. Any sequence of characters that are enclosed in singlequotes will be treated as text and not be used as an expression. Two consecutive singlequotes ("''") are replaced by a singlequote in the output.
Example format strings (assuming that the QDate is the 20 July 1969):
Format | Result |
dd.MM.yyyy | 20.07.1969 |
ddd MMMM d yy | Sun July 20 69 |
'The day is' dddd | The day is Sunday |
If the datetime is invalid, an empty string will be returned.
Definition at line 915 of file qdatetime.cpp.
int QDate::weekNumber | ( | int * | yearNumber = 0 | ) | const |
Returns the week number (1 to 53), and stores the year in {yearNumber} unless yearNumber is null (the default).
Returns 0 if the date is invalid.
In accordance with ISO 8601, weeks start on Monday and the first Thursday of a year is always in week 1 of that year. Most years have 52 weeks, but some have 53.
{yearNumber} is not always the same as year(). For example, 1 January 2000 has week number 52 in the year 1999, and 31 December 2002 has week number 1 in the year 2003.
Copyright (c) 1989 The Regents of the University of California. All rights reserved.
Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, advertising materials, and other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Definition at line 487 of file qdatetime.cpp.
Referenced by QCalendarModel::data().
int QDate::year | ( | ) | const |
Returns the year of this date.
Negative numbers indicate years before 1 A.D. = 1 C.E., such that year -44 is 44 B.C.
Definition at line 353 of file qdatetime.cpp.
Referenced by _q_fixupDateTime(), _q_parseDosDir(), _q_parseUnixDir(), QCalendarWidgetPrivate::_q_slotChangeDate(), QCalendarWidgetPrivate::_q_yearEditingFinished(), QCalendarDayValidator::applyToDate(), QCalendarMonthValidator::applyToDate(), QCalendarWidgetPrivate::createNavigationBar(), QScript::DateTimeToMs(), QLocalePrivate::dateTimeToString(), dayOfYear(), QDB2Result::exec(), QODBCResult::exec(), QPatternist::YearFromAbstractDateTimeFN::extract(), QDB2Driver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QODBCDriver::formatValue(), QPSQLDriver::formatValue(), QPatternist::GYearMonth::fromDateTime(), QPatternist::GYear::fromDateTime(), fromString(), QDateTimeParser::getDigit(), localToUtc(), macDateToString(), macTimeToString(), QCalendarView::moveCursor(), operator<<(), QDateTimeParser::parseSection(), QDateTimeParser::potentialValue(), QCalendarModel::QCalendarModel(), QDateTimeToDATE(), qMakeOraDate(), QCalendarYearValidator::setDate(), QCalendarWidget::setDateRange(), QDateTimeParser::setDigit(), QCalendarWidget::setMaximumDate(), QCalendarWidget::setMinimumDate(), QCalendarWidget::setSelectedDate(), QCalendarWidget::showSelectedDate(), QCalendarWidget::showToday(), QCalendarYearValidator::text(), toString(), QSystemLocalePrivate::toString(), QDateTime::toString(), QCalendarWidgetPrivate::updateCurrentPage(), QCalendarWidgetPrivate::updateMonthMenu(), QMYSQLResult::virtual_hook(), weekNumber(), QPdfEnginePrivate::writeInfo(), and writeMSDosDate().
|
friend |
|
friend |
Definition at line 139 of file qdatetime.h.
|
friend |
Definition at line 140 of file qdatetime.h.
|
private |
Definition at line 137 of file qdatetime.h.
Referenced by addDays(), addMonths(), QDateTimePrivate::addMSecs(), addYears(), currentDate(), QDateTime::currentDateTime(), QDateTime::currentDateTimeUtc(), QDateTime::currentMSecsSinceEpoch(), day(), dayOfWeek(), dayOfYear(), daysInMonth(), daysInYear(), daysTo(), fromJulianDay(), getDate(), month(), operator!=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), setDate(), QDateTime::toMSecsSinceEpoch(), toString(), and year().