租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

qt如何获取当前年月日,qt获取当前程序路径

发布时间:2023-10-23 16:04:21

qt如何获得当前年月日

在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();
}

运行这段代码,将会输出当前的年月日信息。