【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

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM