QCalendar 类

QCalendar 类描述日历系统。 更多...

头: #include <QCalendar>
qmake: QT += core
Since: Qt 5.14

该类在 Qt 5.14 引入。

注意: 此类的所有函数 可重入 .

公共类型

enum class 系统 { Gregorian, Julian, Milankovic, Jalali, IslamicCivil }

公共函数

QCalendar (QStringView name )
QCalendar (QLatin1String name )
QCalendar (QCalendar::System system )
QCalendar ()
QDate dateFromParts (int year , int month , int day ) const
QDate dateFromParts (const QCalendar::YearMonthDay & parts ) const
QString dateTimeToString (QStringView format , const QDateTime & datetime , const QDate & dateOnly , const QTime & timeOnly , const QLocale & locale ) const
int dayOfWeek (QDate date ) const
int daysInMonth (int month , int year = Unspecified) const
int daysInYear (int year ) const
bool hasYearZero () const
bool isDateValid (int year , int month , int day ) const
bool isGregorian () const
bool isLeapYear (int year ) const
bool isLunar () const
bool isLuniSolar () const
bool isProleptic () const
bool isSolar () const
bool isValid () const
int maximumDaysInMonth () const
int maximumMonthsInYear () const
int minimumDaysInMonth () const
QString monthName (const QLocale & locale , int month , int year = Unspecified, QLocale::FormatType format = QLocale::LongFormat) const
int monthsInYear (int year ) const
QString name () const
QCalendar::YearMonthDay partsFromDate (QDate date ) const
QString standaloneMonthName (const QLocale & locale , int month , int year = Unspecified, QLocale::FormatType format = QLocale::LongFormat) const
QString standaloneWeekDayName (const QLocale & locale , int day , QLocale::FormatType format = QLocale::LongFormat) const
QString weekDayName (const QLocale & locale , int day , QLocale::FormatType format = QLocale::LongFormat) const

静态公共成员

QStringList availableCalendars ()

详细描述

A QCalendar object maps a year, month, and day-number to a specific day (ultimately identified by its Julian day number), using the rules of a particular system.

The default QCalendar() is a proleptic Gregorian calendar, which has no year zero. Other calendars may be supported by enabling suitable features or loading plugins. Calendars supported as features can be constructed by passing the QCalendar::System enumeration to the constructor. All supported calendars may be constructed by name, once they have been constructed. (Thus plugins instantiate their calendar backend to register it.) Built-in backends, accessible via QCalendar::System , are also always available by name.

QCalendar 值是不可变的。

另请参阅 QDate and QDateTime .

成员类型文档编制

enum class QCalendar:: 系统

This enumerated type is used to specify a choice of calendar system.

常量 描述
QCalendar::System::Gregorian 0 The default calendar, used internationally.
QCalendar::System::Julian 8 An ancient Roman calendar with too few leap years.
QCalendar::System::Milankovic 9 A revised Julian calendar used by some Orthodox churches.
QCalendar::System::Jalali 10 The Solar Hijri calendar (also called Persian).
QCalendar::System::IslamicCivil 11 The (tabular) Islamic Civil calendar.

另请参阅 QCalendar .

成员函数文档编制

QDate QCalendar:: dateFromParts (const QCalendar::YearMonthDay & parts ) const

QDate QCalendar:: dateFromParts ( int year , int month , int day ) const

把年 月 日转换成 QDate .

year , month ,和 day may be passed as separate numbers or packaged together as the members of parts 。返回 QDate with the given year, month, and day of the month in this calendar, if there is one. Otherwise, including the case where any of the values is QCalendar::Unspecified, returns a QDate whose isNull() is true.

另请参阅 isDateValid () 和 partsFromDate ().

QCalendar:: QCalendar ()

QCalendar:: QCalendar ( QCalendar::System system )

QCalendar:: QCalendar ( QLatin1String name )

QCalendar:: QCalendar ( QStringView name )

Constructs a calendar object.

The choice of calendar to use may be indicated as system , using the enumeration QCalendar::System , or by name , using a string (either Unicode or Latin 1). Construction by name may depend on an instance of the given calendar being constructed by other means first. With no argument, the default constructor returns the Gregorian calendar.

另请参阅 QCalendar , 系统 ,和 isValid ().

[static] QStringList QCalendar:: availableCalendars ()

Returns a list of names of the available calendar systems.

These may be supplied by plugins or other code linked into an application, in addition to the ones provided by Qt, some of which are controlled by features.

QString QCalendar:: dateTimeToString ( QStringView format , const QDateTime & datetime , const QDate & dateOnly , const QTime & timeOnly , const QLocale & locale ) const

Returns a string representing a given date, time or date-time.

datetime is valid, it is represented and format specifiers for both date and time fields are recognized; otherwise, if dateOnly is valid, it is represented and only format specifiers for date fields are recognized; finally, if timeOnly is valid, it is represented and only format specifiers for time fields are recognized. If none of these is valid, an empty string is returned.

QDate::toString and QTime::toString () for the supported field specifiers. Characters in format that are recognized as field specifiers are replaced by text representing appropriate data from the date and/or time being represented. The texts to represent them may depend on the locale specified. Other charagers in format are copied verbatim into the returned string.

另请参阅 monthName (), weekDayName (), QDate::toString (),和 QTime::toString ().

int QCalendar:: dayOfWeek ( QDate date ) const

Returns the day of the week number for the given date .

Returns zero if the calendar is unable to represent the indicated date. Returns 1 for Monday through 7 for Sunday. Calendars with intercallary days may use other numbers to represent these.

另请参阅 partsFromDate () 和 Qt::DayOfWeek .

int QCalendar:: daysInMonth ( int month , int year = Unspecified) const

Returns the number of days in the given month 为给定 year .

Months are numbered consecutively, starting with 1 for the first month of each year. If year is Unspecified (its default, if not passed), the month's length in a normal year is returned.

另请参阅 maximumDaysInMonth () 和 minimumDaysInMonth ().

int QCalendar:: daysInYear ( int year ) const

Returns the number of days in the given year .

Handling of Unspecified as year is undefined.

bool QCalendar:: hasYearZero () const

返回 true if this calendar has a year zero.

A calendar may represent years from its first year onwards but provide no way to describe years before its first; such a calendar has no year zero and is not proleptic.

A calendar which represents years before its first may number these years simply by following the usual integer counting, so that the year before the first is year zero, with negative-numbered years preceding this; such a calendar is proleptic and has a year zero. A calendar might also have a year zero (for example, the year of some great event, with subsequent years being the first year after that event, the second year after, and so on) without describing years before its year zero. Such a calendar would have a year zero without being proleptic.

Some calendars, however, represent years before their first by an alternate numbering; for example, the proleptic Gregorian calendar's first year is 1 CE and the year before it is 1 BCE, preceded by 2 BCE and so on. In this case, we use negative year numbers for this alternate numbering, with year -1 as the year before year 1, year -2 as the year before year -1 and so on. Such a calendar is proleptic but has no year zero.

另请参阅 isProleptic ().

bool QCalendar:: isDateValid ( int year , int month , int day ) const

返回 true precisely if the given year , month ,和 day specify a valid date in this calendar.

Usually this means 1 <= month <= monthsInYear (year) and 1 <= day <= daysInMonth (month, year). However, calendars with intercallary days or months may complicate that.

bool QCalendar:: isGregorian () const

返回 true if this calendar object is the Gregorian calendar object used as default calendar by other Qt APIs, e.g. in QDate .

bool QCalendar:: isLeapYear ( int year ) const

返回 true 若给定 year is a leap year.

Since the year is not a whole number of days long, some years are longer than others. The difference may be a whole month or just a single day; the details vary between calendars.

另请参阅 isDateValid ().

bool QCalendar:: isLunar () const

返回 true if this calendar is a lunar calendar.

A lunar calendar is one based primarily on the phases of the moon.

bool QCalendar:: isLuniSolar () const

返回 true if this calendar is luni-solar.

A luni-solar calendar expresses the phases of the moon but adapts itself to also keep track of the Sun's varying position in the sky, relative to the fixed stars.

bool QCalendar:: isProleptic () const

返回 true if this calendar is proleptic.

A proleptic calendar is able to describe years arbitrarily long before its first. These are represented by negative year numbers and possibly by a year zero.

另请参阅 hasYearZero ().

bool QCalendar:: isSolar () const

返回 true if this calendar is solar.

A solar calendar is based primarily on the Sun's varying position in the sky, relative to the fixed stars.

bool QCalendar:: isValid () const

Returns true if this is a valid calendar object.

Constructing a calendar with an unrecognised calendar name may result in an invalid object. Use this method to check after creating a calendar by name.

int QCalendar:: maximumDaysInMonth () const

Returns the number of days in the longest month in the calendar, in any year.

另请参阅 daysInMonth () 和 minimumDaysInMonth ().

int QCalendar:: maximumMonthsInYear () const

Returns the largest number of months that any year may contain.

另请参阅 monthName (), standaloneMonthName (),和 monthsInYear ().

int QCalendar:: minimumDaysInMonth () const

Returns the number of days in the shortest month in the calendar, in any year.

另请参阅 daysInMonth () 和 maximumDaysInMonth ().

QString QCalendar:: monthName (const QLocale & locale , int month , int year = Unspecified, QLocale::FormatType format = QLocale::LongFormat) const

Returns a suitably localised name for a month.

The month is indicated by a number, with month = 1 meaning the first month of the year and subsequent months numbered accordingly. Returns an empty string if the month number is unrecognized.

year may be Unspecified, in which case the mapping from numbers to names for a typical year's months should be used. Some calendars have leap months that aren't always at the end of the year; their mapping of month numbers to names may then depend on the placement of a leap month. Thus the year should normally be specified, if known.

The name is returned in the form that would normally be used in a full date, in the specified locale format determines how fully it shall be expressed (i.e. to what extent it is abbreviated).

另请参阅 standaloneMonthName (), maximumMonthsInYear (),和 dateTimeToString ().

int QCalendar:: monthsInYear ( int year ) const

Returns the number of months in the given year .

year is Unspecified , returns the maximum number of months in a year.

另请参阅 maximumMonthsInYear ().

QString QCalendar:: name () const

The primary name of this calendar.

QCalendar::YearMonthDay QCalendar:: partsFromDate ( QDate date ) const

转换 QDate to a year, month, and day of the month.

The returned structure's isValid () shall be false if the calendar is unable to represent the given date . Otherwise its year, month, and day members record the so-named parts of its representation.

另请参阅 dateFromParts (), isProleptic (),和 hasYearZero ().

QString QCalendar:: standaloneMonthName (const QLocale & locale , int month , int year = Unspecified, QLocale::FormatType format = QLocale::LongFormat) const

Returns a suitably localised standalone name for a month.

The month is indicated by a number, with month = 1 meaning the first month of the year and subsequent months numbered accordingly. Returns an empty string if the month number is unrecognized.

year may be Unspecified, in which case the mapping from numbers to names for a typical year's months should be used. Some calendars have leap months that aren't always at the end of the year; their mapping of month numbers to names may then depend on the placement of a leap month. Thus the year should normally be specified, if known.

The name is returned in the form that would be used in isolation in the specified locale format determines how fully it shall be expressed (i.e. to what extent it is abbreviated).

另请参阅 monthName (), maximumMonthsInYear (),和 dateTimeToString ().

QString QCalendar:: standaloneWeekDayName (const QLocale & locale , int day , QLocale::FormatType format = QLocale::LongFormat) const

Returns a suitably localised standalone name for a day of the week.

The days of the week are numbered from 1 for Monday through 7 for Sunday. Some calendars may support higher numbers for other days (e.g. intercallary days, that are not part of any week). Returns an empty string if the day number is unrecognized.

The name is returned in the form that would be used in isolation (for example as a column heading in a calendar's tabular display of a month with successive weeks as rows) in the specified locale format determines how fully it shall be expressed (i.e. to what extent it is abbreviated).

另请参阅 weekDayName () 和 dayOfWeek ().

QString QCalendar:: weekDayName (const QLocale & locale , int day , QLocale::FormatType format = QLocale::LongFormat) const

Returns a suitably localised name for a day of the week.

The days of the week are numbered from 1 for Monday through 7 for Sunday. Some calendars may support higher numbers for other days (e.g. intercallary days, that are not part of any week). Returns an empty string if the day number is unrecognized.

The name is returned in the form that would normally be used in a full date, in the specified locale format determines how fully it shall be expressed (i.e. to what extent it is abbreviated).

另请参阅 standaloneWeekDayName () 和 dayOfWeek ().