C++QT13位时间戳转换成年月日时分秒毫秒
前一阵子做了一个qt的项目,然后数据库中显示的是13位的bigInt型的数据,但在QTableWidget中需要显示带毫秒级的时间格式,所以多方查询,以防下次用到,就记录下。
1.QString 和QDateTime的时间转换
(1).QDateTime转换成QString
QDateTime dataTime;
QString startTime;
startTime=dataTime.toString("yyyy-MM-dd hh:mm:ss");
(2).QString 转换成QDateTime
QDateTime dataTime;
QString startTime;
dataTime= QDateTime::fromString(startTime, "yyyy-MM-dd hh:mm:ss");
2.年月日时分秒毫秒和13位时间戳的转换
(1)年月日时分秒转换成13位时间戳
数据库中的时间是13位bigInt型数据:1552535825000,转换成时间模式,界面显示:2019-03-14 11:57:05。
QDateTime startTime_d=QDateTime::fromString(startTime