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();
}
このコードを実行すると、現在の日付が表示されます。