1 Format Output Current moment
Qdebug () << "currenttime--" <<qtime::currenttime (). toString (qt::isodate)
<<qdatetime:: Currentdatetime (). ToString (qt::isodate)
<<qdatetime::currentdatetime (). ToString ("Yyyy-mm-dd hh:mm:ss: Zzz ");
The output is:
currenttime--"16:03:27" "
2016-02-24t16:03:27" "
2016-02-24 16:03:27:607"
2 Get the number of seconds since 1970-01-01 and turn this description into a date
int I=qdatetime::currentdatetime (). totime_t ();
Qdebug () << "i--" <<i;
Qdebug () <<qdatetime::fromtime_t (i). toString ("Yyyy-mm-dd hh:mm:ss.zzz");
The output is:
i--1458134574
"2016-03-16 21:22:54.000"
3 Gets the current time into a string form and converts the string of this time to the date
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");
The output is:
time--"2016-03-16 21:26:00.635"
"2016-03-16 21:26:00.635"
3 Qdatetime plus a certain number of seconds
Qdatetime provides these functions to provide an operation to increase the number of minutes from the date to the data.
Qdatetime datetime=qdatetime::currentdatetime ();
Qdatetime datetime2=datetime.addsecs (7000000000);
Qdebug () <<datetime.tostring (qt::isodate)
<<datetime2.tostring (qt::isodate);
The output is:
Starting F:\exercise\build-untitled20-desktop4_8_5-Debug\debug\untitled20.exe ...