温馨提示×

qt怎么获取当前年月日

qt
小亿
280
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