QT uses the Qtime class to control time, here is a brief introduction to the use of Qtime member functions:

Source: Internet
Author: User

QT uses the Qtime class to control time, here is a brief introduction to the use of Qtime member functions:

--------------------------------------------------------------------------------------------------------------- -------------------------

Qtime::qtime ()
A default constructor that constructs a time, minutes, and seconds of 0, such as 00:00:00.000 (midnight)

Qtime::qtime (int h, int m, int s=0, int ms = 0)
Constructs a user-specified time, minutes, seconds.
The valid values for the parameters are:
H:0--23
m:0--59
ms:0--999

Qtime qtime::addmsecs (int ms) const
Returns a Time object after the current time object, or before or after Ms milliseconds (before or after the sign of MS, as if it were a regular, before the reverse)
such as: Qtime time (3,0,0);
Qtime newTime1 = time.addmsecs (1000);
Qtime newTime2 = time.addmsecs (-1000);
The newTime1 is a delay of 1000 milliseconds or 1 seconds (03:00:01.000) longer than the time specified (03:00:00.000), while newTime2 1000 milliseconds in advance (02:59:59.000)

Qtime qtime::addsecs (int nsecs) const
Same as Addmsecs (), except that nsecs units are seconds. Returns a Time object before or after the current time object.

int qtime::elapsed () const
Returns the number of milliseconds that the last call to start () or restart () has elapsed. If after 24 hours, the counter is set 0. If the system time setting changes, the result is indeterminate.

int Qtime::hour () const
Returns the hour of the time object, the range of values (0--23)

int Qtime::minute () const
Returns the minute of the time object, the range of values (0--59)

int Qtime::second () const
Returns the seconds of the time object, the range of values (0--59)

int qtime::msec () const
Returns the milliseconds of the time object, the range of values (0--999)

BOOL Qtime::isnull () const
Returns true if the time object is equal to 00:00:00.000, or false instead.

BOOL Qtime::isvalid () const
Returns true if the time object is valid, or false instead. (i.e.: hours, minutes, seconds, milliseconds are within its value range)

int Qtime::msecsto (const qtime &t) const
Returns the number of milliseconds between the current time object and the time specified by T. If T is earlier than the time of the current time object, the value returned is negative. Because the time of day is 86400000 milliseconds, the return value range is -86400000--86400000

int Qtime::secsto (const qtime &t) const
is basically the same as Msecsto (), just returns the number of seconds, and the valid range of the return value is -86400--86400

int Qtime::restart ()
Sets the current time object's value to the current system time, and returns the number of milliseconds from the last call to start () or restart () to the present. If the counter exceeds 24 hours, then set 0. If the system time setting changes when the counter counts, the result is indeterminate.

BOOL Qtime::sethms (int h, int m, int s, int ms = 0)
Sets the time, minutes, seconds, and milliseconds of the current object. Returns true if the given parameter value is valid, otherwise false.

void Qtime::start ()
Setting the current time object's value to the current system time, this function is actually combined with restart () and elapsed () to count.

QString qtime::tostring (const QString &format) const
Outputs the time of the current time object as a string in the format specified by the parameter format.
The parameter format is used to specify the output format when, minutes, seconds, and milliseconds. (hh:mm:ss.zzz)
H: Indicates hours, range is 0--23
HH: Two-digit hour, less than two bits of the front with 0, such as (0 points: 00, 3 points: 03, 11 points: 11)
M: Indicates minutes, range 0--59
MM: With two digits for the minute, less than two bits of the front with 0 to complement.
S: Indicates seconds, range 0--59
SS: With two digits for the second, less than two bits of the front with 0 to complement.
Z: Indicates milliseconds, range 0--999
ZZZ: A three-digit millisecond, less than three bits of the front with 0 complement.
AP: Displayed with AM/PM.
AP: Displayed with AP/PM.
For example:
Qtime time (14,3,9,42);//Set to 14:03:09.042
QString i = time.tostring ("hh:mm:ss.zzz");//result is 14:03:09.042
QString j = time.tostring ("h:m:s.z");//result is 14:3:9.42
QString m = time.tostring ("H:m:s.z AP");//result is 2:3:9.42 PM
QString n = time.tostring ("h:m:s.z ap");//result is 2:3:9.42 pm

QString qtime::tostring (Qt::D ateformat f = qt::textdate) const
Outputs the time of the current time object as a string in the format specified by the parameter format.
Optional values for parameters:
Qt::textdate: Format is HH:MM:SS
Qt::isodate: Follow the ISO8601 time representation format, also for HH:MM:SS
Qt::localdate: String format relies on system Local settings

--------------------------------------------------------------------------------------------------------------- -------------------------

Static member functions:

Qtime Qtime::currenttime ()
Returns the current system time.

Qtime qtime::fromstring (const QString &string, Qt::D ateformat format = qt::textdate)
Returns a time object using the format specified by the parameter format, based on the time specified by the parameter string. If the time specified by the string is not valid, an invalid time object is returned.
Format selectable values:
Qt::textdate: Format is HH:MM:SS
Qt::isodate: Follow the ISO8601 time representation format, also for HH:MM:SS
Qt::localdate: String format relies on system Local settings

Qtime qtime::fromstring (const QString &string, const QString &format)
Returns a time object using the format specified by the parameter format, based on the time specified by the parameter string. If the time specified by the string is not valid, an invalid time object is returned.
Format formats are referred to QString qtime::tostring (const QString &format) Const.

BOOL Qtime::isvalid (int h, int m, int s, int ms = 0)
Returns true if the time specified by the parameter is valid, or false.

--------------------------------------------------------------------------------------------------------------- -------------------------

Static member functions are not dependent on objects and can be called directly through a class, regardless of the object:

Example: You do not need to define a Qtime object when getting the hour portion of the current system time

int hour = Qtime::currenttime (). Hour ()

QT uses the Qtime class to control time, here is a brief introduction to the use of Qtime member functions:

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.