2014年03月04日 星期二 09:34
QDateTime提供了与日期和时间的相关操作方法。
A QDateTime object contains a calendar date and a clock time (a "datetime"). It is a combination of the QDate and QTime classes. It can read the current datetime from the system clock. It provides functions for comparing datetimes and for manipulating a datetime by adding a number of seconds, days, months, or years.
编程示例如下:
#include <QCoreApplication>
#include <QtCore>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
auto dt=QDateTime::currentDateTime();
qDebug() << dt;
auto birthday=QDateTime::fromString("19820925","yyyyMMdd");
qDebug() << birthday;
qDebug() << birthday.toString();
qDebug() << birthday.toString("yyyy-MM-dd");
qDebug() << dt.date();
qDebug() << dt.time();
qDebug() << birthday.daysTo(dt);
return a.exec();
}
参考资料:
Zeuux © 2025
京ICP备05028076号