溫馨提示×

qt怎么獲取當前年月日

qt
小億
647
2023-10-23 16:04:21
欄目: 編程語言

在Qt中,可以使用QDate類來獲取當前年月日??梢酝ㄟ^QDate::currentDate()靜態函數來獲取當前日期,然后使用QDate的成員函數year()、month()和day()來獲取年、月和日。

下面是一個示例代碼:

#include <QCoreApplication>
#include <QDate>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QDate currentDate = QDate::currentDate();
    int year = currentDate.year();
    int month = currentDate.month();
    int day = currentDate.day();

    qDebug() << "當前日期:" << year << "年" << month << "月" << day << "日";

    return a.exec();
}

運行這段代碼,將會輸出當前的年月日信息。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女