【Qt开发】QDate类

QDate为开发者提供日期的类,函数也很丰富

常用方法介绍

 

1.QDate addDays(qint64 ndays) const

    当前日期添加n天,n可以为负

2.QDate addMonths(int nmonths) const

    当前日期添加n月,n可以为负

3.QDate addYears(int nyears) const

    当前日期添加n年,n可以为负

4.int day() const

    返回所处月的天数(1到31)

5.int month() const

    返回日期的月数

6.int year() const

    返回日期的年数

7.int dayOfWeek() const

    返回周几(1到7),0表示日期无效

8.int dayOfYear() const

    返回所处年的天数(1~365/366)

9.int daysInMonth() const

    返回当前月共多少天(28~31)

10.int daysInYear() const

    返回当前年共多少天(365/366)

11.qint64 daysTo(const QDate &d) const

    返回当前日期到d的天数,可为负

12.void getDate(int *year, int *month, int *day) const

    提取日期的年、月和日,并将它们分配给*年、*月和*日。指针可以为空。

13.bool isNull() const

    判断日期对象是否为NULL

14.bool isValid() const

    判断日期对象是否有效,如月的范围(1~12),不在此范围为无效日期

15.bool setDate(int year, int month, int day)

    设置日期

16.QDate static currentDate()

    获得当前日期

17.bool static isLeapYear(int year)

    判断year是否为闰年

18.QString toString(const QString &format) const

    按照format格式转换成日期QString

19.QDate static fromString(const QString & string, const QString & format)

    按照规则生成QDate

时间格式显示

d    一位表示天数(1到31)

dd   两位表示天数(01到31)

ddd   英文简写表示('Mon' to 'Sun')

dddd  英文全写表示( 'Monday' to 'Sunday')

M    一位表示月数(1到12)

MM    两位表示月数(01到12)

MMM   英文简写表示 ('Jan' to 'Dec')

MMMM  英文全写表示 ( 'January' to 'December')

yy   两位表示年数(00 to 99)

yyyy  年数用四位数表示,如年为负数,则在前面加上一个负号

 

例:

dd.MM.yyyy       21.08.2016

ddd MMMM d yy     Sun July 20 69

'The day is' dddd   The day is Sunday

  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码农code之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值