QT获取当前系统时间并格式化

QT获取当前系统时间并格式化用到类


#include <QDate>
#include <QTime>
#include <QDateTime>

获取日期时间并格式化


QDate::currentDate().toString("yyyy-MM-dd");
QTime::currentTime().toString("HH:mm:ss");
QTime::currentTime().toString("HH:mm:ss zzz");
QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss:zzz")

若需要输出,则

QString time;
time=QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss:zzz");
qDebug()<<time;

猜你喜欢

转载自blog.csdn.net/weixin_43155866/article/details/88556312