1、主要有时间戳->QDateTime,QDateTime->QString
2、同时QString->QDateTime,QDateTime->时间戳
详情见代码:
//QDateTime转时间戳
qint64 time = QDateTime::currentSecsSinceEpoch();
double nowTime = (double)time;
qDebug()<<"nowTime1111=="<<nowTime;
//时间戳转QDateTime,QDateTime转QString
QString strTime = QDateTime::fromSecsSinceEpoch(time).toString("yyyy-MM-dd hh:mm:ss");
qDebug()<<"strTime11111==="<<strTime;
qDebug()<<"=======================================";
//QString转QDateTime
QDateTime dateTime = QDateTime::fromString(strTime, "yyyy-MM-dd hh:mm:ss");
//QDateTime又转时间戳
qint64 timeTemp = dateTime.toSecsSinceEpoch();
double nowTime2 = (double)timeTemp;
qDebug()<<"nowTime2222=="<<nowTime2;
QString strTime2 = QDateTime::fromSecsSinceEpoch(timeTemp).toString("yyyy-MM-dd hh:mm:ss");
qDebug()<<"strTime222222==="<<strTime2;