Qt gets the current time and formats the output and converts the product seconds to time __QT

Source: Internet
Author: User
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 ...








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.