QT-Qt获取当前时间并格式化输出及将积秒转换成时间
https://blog.csdn.net/u012199908/article/details/50731543
?
?
格式化輸出當(dāng)前時(shí)刻
qDebug()<<"currentTime--"<<QTime::currentTime().toString(Qt::ISODate)
<<QDateTime::currentDateTime().toString(Qt::ISODate)
<<QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:zzz");
輸出為:
currentTime--
"16:03:27"
"2016-02-24T16:03:27"
"2016-02-24 16:03:27:607"
2 ?獲得1970-01-01至今的秒數(shù)并將這個(gè)描述轉(zhuǎn)成日期
int i=QDateTime::currentDateTime().toTime_t();
qDebug()<<"i--"<<i;
qDebug()<<QDateTime::fromTime_t(i).toString("yyyy-MM-dd hh:mm:ss.zzz");
輸出為:
i-- 1458134574
"2016-03-16 21:22:54.000"
3 獲得當(dāng)前的時(shí)間轉(zhuǎn)成字符串形式,并且將這個(gè)時(shí)間的字符串轉(zhuǎn)成當(dāng)時(shí)日期
QString s=QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz");
QDateTime dateTime=QDateTime::fromString(s,"yyyy-MM-dd hh:mm:ss.zzz");
qDebug()<<"time--"<<s;
qDebug()<<dateTime.toString("yyyy-MM-dd hh:mm:ss.zzz");
輸出為:
time-- "2016-03-16 21:26:00.635"
"2016-03-16 21:26:00.635"
3 QDateTime加一定秒數(shù)
?
QDateTime提供了這些函數(shù)來提供向數(shù)據(jù)中增加年月日時(shí)分秒的操作。
QDateTime dateTime=QDateTime::currentDateTime();
QDateTime dateTime2=dateTime.addSecs(7000000000);
qDebug()<<dateTime.toString(Qt::ISODate)
<<dateTime2.toString(Qt::ISODate);
輸出為:
Starting F:\exercise\build-untitled20-desktop4_8_5-Debug\debug\untitled20.exe...
"2016-03-21T22:12:44" "1965-11-02T21:42:52"
---------------------
作者:yingge2017
來源:CSDN
原文:https://blog.csdn.net/u012199908/article/details/50731543
版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請(qǐng)附上博文鏈接!
轉(zhuǎn)載于:https://www.cnblogs.com/FKdelphi/p/10443865.html
總結(jié)
以上是生活随笔為你收集整理的QT-Qt获取当前时间并格式化输出及将积秒转换成时间的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: URL与URI的不同
- 下一篇: 【c++进阶:c++ 顺序容器vecto