Qt QDate

QDate类提供日期功能,包括从系统时钟读取当前日期、比较日期、操作日期等。可以创建包含具体年月日的QDate对象,通过静态函数获取当前日期,或使用字符串转换。提供了日期加减天数、月份、年份的功能,以及判断是否为闰年的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Public Functions

 

 

QDate()

 

QDate(int y, int m, int d)

QDate

addDays(qint64 ndays) const

QDate

addMonths(int nmonths) const

QDate

addYears(int nyears) const

int

day() const

int

dayOfWeek() const

int

dayOfYear() const

int

daysInMonth() const

int

daysInYear() const

qint64

daysTo(const QDate &d) const

void

getDate(int *year, int *month, int *day) const

bool

isNull() const

bool

isValid() const

int

month() const

bool

setDate(int year, int month, int day)

qint64

toJulianDay() const

QString

toString(const QString &format) const

QString

toString(Qt::DateFormat format = Qt::TextDate) const

int

weekNumber(int *yearNumber = Q_NULLPTR) const

int

year() 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 Members

 

QDate

currentDate()

QDate

fromJulianDay(qint64 jd)

QDate

fromString(const QString &string, Qt::DateFormat format = Qt::TextDate)

QDate

fromString(const QString &string, const QString &format)

bool

isLeapYear(int year)

bool

isValid(int year, int month, int day)

QString

longDayName(int weekday, MonthNameType type = DateFormat)

QString

longMonthName(int month, MonthNameType type = DateFormat)

QString

shortDayName(int weekday, MonthNameType type = DateFormat)

QString

shortMonthName(int month, MonthNameType type = DateFormat)

Related Non-Members

 

QDataStream &

operator<<(QDataStream &out, const QDate &date)

QDataStream &

operator>>(QDataStream &in, QDate &date)

 

Detailed Description

The QDate class provides date functions.

A QDate object contains a calendar date, i.e. year, month, and day numbers, in the Gregorian calendar. 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 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.

No Year 0

There is no year 0. Dates in that year are considered invalid. The year -1 is the year "1 before Christ" or "1 before current era." The day before 1 January 1 CE is 31 December 1 BCE.

Range of Valid Dates

Dates are stored internally as a Julian Day number, an integer count of every day in a contiguous range, with 24 November 4714 BCE in the Gregorian calendar being Julian Day 0 (1 January 4713 BCE in the Julian calendar). As well as being an efficient and accurate way of storing an absolute date, it is suitable for converting a Date into other calendar systems such as Hebrew, Islamic or Chinese. The Julian Day number can be obtained using QDate::toJulianDay() and can be set using QDate::fromJulianDay().

The range of dates able to be stored by QDate as a Julian Day number is for technical reasons limited to between -784350574879 and 784354017364, which means from before 2 billion BCE to after 2 billion CE.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值