Qtime class Introduction

Source: Internet
Author: User

In QT, The qtime class is used to control the time. Here we will briefly introduce the usage of the qtime member functions:

Certificate ----------------------------------------------------------------------------------------------------------------------------------------

Qtime: qtime ()
The default constructor is used to construct a time, minute, and second, for example, 00:00:00. 000 (midnight)

Qtime: qtime (int h, int M, int S = 0, int MS = 0)
Construct a user-defined time, minute, and second.
The valid values are as follows:
H: 0--23
M: 0--59
MS: 0--999

Qtime: addmsecs (int ms) const
Returns a time object after the current time object or milliseconds before (or after the MS symbol, for example, after the regular expression, otherwise)
For example, qtime time (3, 0, 0 );
Qtime newtime1 = time. addmsecs (1000 );
Qtime newtime2 = time. addmsecs (-1000 );
Newtime1 is a delay of 1000 milliseconds (that is, 1 second) than the time specified (03:00:00. 000), while newtime2 is 1000 milliseconds in advance (03:00:01. 000)

Qtime: addsecs (INT nsecs) const
It is the same as addmsecs (), but the unit of nsecs is second. That is, a time object before or after the current time object is returned.

Int qtime: elapsed () const
Returns the number of milliseconds that have elapsed since the last call of START () or restart. if 24 hours later, the counter is set to 0. if the system time settings change, the results are not clear.

Int qtime: hour () const
Returns the hour of the time object. value range: (0--23)

Int qtime: minute () const
Returns the minute of the time object. value range: (0--59)

Int qtime: Second () const
The second of the returned time object. value range: (0--59)

Int qtime: msec () const
The millisecond of the returned time object. value range: (0--999)

Bool qtime: isnull () const
If the time object is equal to 00:00:00. 000, true is returned; otherwise, false is returned.

Bool qtime: isvalid () const
If the time object is valid, true is returned; otherwise, false is returned (namely, the time, minute, second, and millisecond are within the value range)

Int qtime: msecsto (const qtime & T) const
Returns the number of milliseconds from the current time object to the time specified by T. if t is earlier than the current time, the returned value is a negative value. because the time of one day is 86400000 milliseconds, the returned value range is-86400000--86400000.

Int qtime: secsto (const qtime & T) const
It is basically the same as msecsto (), but only returns the number of seconds. The valid range of the returned value is-86400--86400.

Int qtime: restart ()
Set the value of the current time object to the current system time, and return the number of milliseconds from the last call of START () or restart () to the present. if the counter exceeds 24 hours, set it to 0. if the system time setting changes when the counter is counted, the result is uncertain.

Bool qtime: sethms (int h, int M, int S, int MS = 0)
Sets the hour, minute, second, and millisecond of the current time object. If the specified parameter value is valid, true is returned; otherwise, false is returned.

Void qtime: Start ()
Set the value of the current time object to the current system time. This function is used in combination with restart () and elapsed () for counting.

Qstring qtime: tostring (const qstring & format) const
Output the time of the current time object in string format according to the format specified by the parameter format.
The format parameter refers to the output format of the timing, minute, second, and millisecond. For example, (HH: mm: Ss. ZZZ)
H: indicates the hour. The value range is 0--23.
Hh: two digits are used to represent the hour, and the first two digits are supplemented with 0, for example)
M: minute, range: 0--59
MM: two digits are used to represent the minute, and the first two digits are filled with 0.
S: indicates the second. The value range is 0--59.
SS: two digits are used to represent the second, and the first two digits are supplemented with 0.
Z: milliseconds in the range of 0--999
Zzz: represented by three digits in milliseconds. the first digit of less than three digits is supplemented by 0.
AP: displayed in AM/PM.
AP: displayed in AP/PM.
For example:
Qtime time (,); // set the time To 14:03:09. 042
Qstring I = time. tostring ("HH: mm: Ss. Zzz"); // The result is 14:03:09. 042
Qstring J = time. tostring ("H: M: S. Z"); // The result is. 42
Qstring M = time. tostring ("H: M: S. z ap"); // The result is. 42 pm.
Qstring n = time. tostring ("H: M: S. z ap"); // The result is. 42 pm.

Qstring qtime: tostring (QT: dateformat F = QT: textdate) const
Output the time of the current time object in string format according to the format specified by the parameter format.
Optional values:
Qt: textdate: Format: hh: mm: SS
Qt: isodate: follows the time format of iso8601, which is also hh: mm: SS
Qt: localdate: the string format depends on the local settings of the system.

Certificate ----------------------------------------------------------------------------------------------------------------------------------------

Static member functions:

Qtime: currenttime ()
Returns the current system time.

Qtime: fromstring (const qstring & string, QT: dateformat format = QT: textdate)
Return a time object according to the time specified by the string parameter using the format specified by the parameter. If the time specified by string is invalid, an invalid time object is returned.
Value Options:
Qt: textdate: Format: hh: mm: SS
Qt: isodate: follows the time format of iso8601, which is also hh: mm: SS
Qt: localdate: the string format depends on the local settings of the system.

Qtime: fromstring (const qstring & string, const qstring & format)
A time object is returned based on the time specified by the string parameter in the format specified. If the time specified by the string is invalid, an invalid time object is returned.
For the format of format, see qstring qtime: tostring (const qstring & format) Const.

Bool qtime: isvalid (int h, int M, int S, int MS = 0)
If the time specified by the parameter is valid, true is returned; otherwise, false is returned.

Certificate ----------------------------------------------------------------------------------------------------------------------------------------

Static member functions are independent of objects and can be called directly through classes. They are irrelevant to objects:

For example, when obtaining the hour of the current system time, you do not need to define a qtime object.

Int hour = qtime: currenttime (). Hour ()

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.