一、QDate类:
    QDate 类可以封装日期信息也可以通过这个类得到日期相关的信息,包括: 年 , 月 , 日

    1. // 构造函数
    2. QDate::QDate();
    3. QDate::QDate(int y, int m, int d);
    4. // 公共成员函数
    5. // 重新设置日期对象中的日期
    6. bool QDate::setDate(int year, int month, int day);
    7. // 给日期对象添加 ndays 天
    8. QDate QDate::addDays(qint64 ndays) const;
    9. // 给日期对象添加 nmonths 月
    10. QDate QDate::addMonths(int nmonths) const;
    11. // 给日期对象添加 nyears 月
    12. QDate QDate::addYears(int nyears) const;
    13. // 得到日期对象中的年/月/日
    14. int QDate::year() const;
    15. int QDate::month() const;
    16. int QDate::day() const;
    17. void QDate::getDate(int *year, int *month, int *day) const;
    18. // 日期对象格式化
    19. /*
    20. d - The day as a number without a leading zero (1 to 31)
    21. dd - The day as a number with a leading zero (01 to 31)
    22. ddd - The abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses the system locale to localize the name, i.e. QLocale::system().
    23. dddd - The long localized day name (e.g. 'Monday' to 'Sunday'). Uses the system locale to localize the name, i.e. QLocale::system().
    24. M - The month as a number without a leading zero (1 to 12)
    25. MM - The month as a number with a leading zero (01 to 12)
    26. MMM - The abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses the system locale to localize the name, i.e. QLocale::system().
    27. MMMM - The long localized month name (e.g. 'January' to 'December'). Uses the system locale to localize the name, i.e. QLocale::system().
    28. yy - The year as a two digit number (00 to 99)
    29. yyyy - The year as a four digit number. If the year is negative, a minus sign is prepended, making five characters.
    30. */
    31. QString QDate::toString(const QString &format) const;
    32. // 操作符重载 ==> 日期比较
    33. bool QDate::operator!=(const QDate &d) const;
    34. bool QDate::operator<(const QDate &d) const;
    35. bool QDate::operator<=(const QDate &d) const;
    36. bool QDate::operator==(const QDate &d) const;
    37. bool QDate::operator>(const QDate &d) const;
    38. bool QDate::operator>=(const QDate &d) const;
    39. // 静态函数 -> 得到本地的当前日期
    40. [static] QDate QDate::currentDate();

    二、QTime类:
    QTime 类可以封装时间信息也可以通过这个类得到时间相关的信息,包括: 时 , 分 , 秒 , 毫秒

    1. // 构造函数
    2. QTime::QTime();
    3. /*
    4. h ==> 取值范围: 0 ~ 23
    5. m and s ==> 取值范围: 0 ~ 59
    6. ms ==> 取值范围: 0 ~ 999
    7. */
    8. QTime::QTime(int h, int m, int s = 0, int ms = 0);
    9. // 公共成员函数
    10. // Returns true if the set time is valid; otherwise returns false.
    11. bool QTime::setHMS(int h, int m, int s, int ms = 0);
    12. QTime QTime::addSecs(int s) const;
    13. QTime QTime::addMSecs(int ms) const;
    14. // 示例代码
    15. QTime n(14, 0, 0); // n == 14:00:00
    16. QTime t;
    17. t = n.addSecs(70); // t == 14:01:10
    18. t = n.addSecs(-70); // t == 13:58:50
    19. t = n.addSecs(10 * 60 * 60 + 5); // t == 00:00:05
    20. t = n.addSecs(-15 * 60 * 60); // t == 23:00:00
    21. // 从时间对象中取出 时/分/秒/毫秒
    22. // Returns the hour part (0 to 23) of the time. Returns -1 if the time is invalid.
    23. int QTime::hour() const;
    24. // Returns the minute part (0 to 59) of the time. Returns -1 if the time is invalid.
    25. int QTime::minute() const;
    26. // Returns the second part (0 to 59) of the time. Returns -1 if the time is invalid.
    27. int QTime::second() const;
    28. // Returns the millisecond part (0 to 999) of the time. Returns -1 if the time is invalid.
    29. int QTime::msec() const;
    30. // 时间格式化
    31. /*
    32. -- 时 --
    33. h ==> The hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
    34. hh ==> The hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
    35. H ==> The hour without a leading zero (0 to 23, even with AM/PM display)
    36. HH ==> The hour with a leading zero (00 to 23, even with AM/PM display)
    37. -- 分 --
    38. m ==> The minute without a leading zero (0 to 59)
    39. mm ==> The minute with a leading zero (00 to 59)
    40. -- 秒 --
    41. s ==> The whole second, without any leading zero (0 to 59)
    42. ss ==> The whole second, with a leading zero where applicable (00 to 59)
    43. -- 毫秒 --
    44. zzz ==> The fractional part of the second, to millisecond precision,
    45. including trailing zeroes where applicable (000 to 999).
    46. -- 上午或者下午
    47. AP or A ==> 使用AM/PM(大写) 描述上下午, 中文系统显示汉字
    48. ap or a ==> 使用am/pm(小写) 描述上下午, 中文系统显示汉字
    49. */
    50. QString QTime::toString(const QString &format) const;
    51. // 阶段性计时
    52. // 过时的API函数
    53. // 开始计时
    54. void QTime::start();
    55. // 计时结束
    56. int QTime::elapsed() const;
    57. // 重新计时
    58. int QTime::restart();
    59. // 推荐使用的API函数
    60. // QElapsedTimer 类
    61. void QElapsedTimer::start();
    62. qint64 QElapsedTimer::restart();
    63. qint64 QElapsedTimer::elapsed() const;
    64. // 操作符重载 ==> 时间比较
    65. bool QTime::operator!=(const QTime &t) const;
    66. bool QTime::operator<(const QTime &t) const;
    67. bool QTime::operator<=(const QTime &t) const;
    68. bool QTime::operator==(const QTime &t) const;
    69. bool QTime::operator>(const QTime &t) const;
    70. bool QTime::operator>=(const QTime &t) const;
    71. // 静态函数 -> 得到当前时间
    72. [static] QTime QTime::currentTime();

    三、QDateTime类:
    QDateTime 类可以封装日期和时间信息也可以通过这个类得到日期和时间相关的信息,包括: 年 , 月 , 日 , 时 , 分 , 秒 , 毫秒。其实这个类就是 QDate 和 QTime 这两个类的结合体

    1. // 构造函数
    2. QDateTime::QDateTime();
    3. QDateTime::QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec = Qt::LocalTime);
    4. // 公共成员函数
    5. // 设置日期
    6. void QDateTime::setDate(const QDate &date);
    7. // 设置时间
    8. void QDateTime::setTime(const QTime &time);
    9. // 给当前日期对象追加 年/月/日/秒/毫秒, 参数可以是负数
    10. QDateTime QDateTime::addYears(int nyears) const;
    11. QDateTime QDateTime::addMonths(int nmonths) const;
    12. QDateTime QDateTime::addDays(qint64 ndays) const;
    13. QDateTime QDateTime::addSecs(qint64 s) const;
    14. QDateTime QDateTime::addMSecs(qint64 msecs) const;
    15. // 得到对象中的日期
    16. QDate QDateTime::date() const;
    17. // 得到对象中的时间
    18. QTime QDateTime::time() const;
    19. // 日期和时间格式, 格式字符参考QDate 和 QTime 类的 toString() 函数
    20. QString QDateTime::toString(const QString &format) const;
    21. // 操作符重载 ==> 日期时间对象的比较
    22. bool QDateTime::operator!=(const QDateTime &other) const;
    23. bool QDateTime::operator<(const QDateTime &other) const;
    24. bool QDateTime::operator<=(const QDateTime &other) const;
    25. bool QDateTime::operator==(const QDateTime &other) const;
    26. bool QDateTime::operator>(const QDateTime &other) const;
    27. bool QDateTime::operator>=(const QDateTime &other) const;
    28. // 静态函数
    29. // 得到当前时区的日期和时间(本地设置的时区对应的日期和时间)
    30. [static] QDateTime QDateTime::currentDateTime();