QTime Class Reference |
Expression | Output |
---|---|
h | the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) |
hh | the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) |
m | the minute without a leading zero (0 to 59) |
mm | the minute with a leading zero (00 to 59) |
s | the second whithout a leading zero (0 to 59) |
ss | the second whith a leading zero (00 to 59) |
z | the milliseconds without leading zeroes (0 to 999) |
zzz | the milliseconds with leading zeroes (000 to 999) |
AP | interpret as an AM/PM time. AP must be either "AM" or "PM". |
ap | Interpret as an AM/PM time. ap must be either "am" or "pm". |
All other input characters will be treated as text. Any sequence of characters that are enclosed in single quotes will also be treated as text and not be used as an expression.
QTime time = QTime::fromString("1mm12car00", "m'mm'hcarss"); // time is 12:01.00
If the format is not satisfied an invalid QTime is returned. Expressions that do not expect leading zeroes to be given (h, m, s and z) are greedy. This means that they will use two digits even if this puts them outside the range of accepted values and leaves too few digits for other sections. For example, the following string could have meant 00:07:10, but the m will grab two digits, resulting in an invalid time:
QTime time = QTime::fromString("00:710", "hh:ms"); // invalid
Any field that is not represented in the format will be set to zero. For example:
QTime time = QTime::fromString("1.30", "m.s"); // time is 00:01:30.000
QDateTime::toString() QTime::toString()
See also QDateTime::fromString(), QDate::fromString(), and QDate::toString().
Returns the hour part (0 to 23) of the time.
See also minute(), second(), and msec().
Returns true if the time is null; otherwise returns false. A null time is also an invalid time.
See also isValid().
Returns true if the time is valid; otherwise returns false. For example, the time 23:30:55.746 is valid, but 24:12:30 is invalid.
See also isNull().
This is an overloaded member function, provided for convenience.
Returns true if the specified time is valid; otherwise returns false.
The time is valid if h is in the range 0 to 23, m and s are in the range 0 to 59, and ms is in the range 0 to 999.
Example:
QTime::isValid(21, 10, 30); // returns true QTime::isValid(22, 5, 62); // returns false
Returns the minute part (0 to 59) of the time.
See also hour(), second(), and msec().
Returns the millisecond part (0 to 999) of the time.
See also hour(), minute(), and second().
Returns the number of milliseconds from this time to t. If t is earlier than this time, the number of milliseconds returned is negative.
Because QTime measures time within a day and there are 86400 seconds in a day, the result is always between -86400000 and 86400000 msec.
See also secsTo() and addMSecs().
Sets this time to the current time and returns the number of milliseconds that have elapsed since the last time start() or restart() was called.
This function is guaranteed to be atomic and is thus very handy for repeated measurements. Call start() to start the first measurement, and restart() for each later measurement.
Note that the counter wraps to zero 24 hours after the last call to start() or restart().
Warning: If the system's clock setting has been changed since the last time start() or restart() was called, the result is undefined. This can happen when daylight savings time is turned on or off.
See also start(), elapsed(), and currentTime().
Returns the second part (0 to 59) of the time.
See also hour(), minute(), and msec().
Returns the number of seconds from this time to t. If t is earlier than this time, the number of seconds returned is negative.
Because QTime measures time within a day and there are 86400 seconds in a day, the result is always between -86400 and 86400.
See also addSecs() and QDateTime::secsTo().
Sets the time to hour h, minute m, seconds s and milliseconds ms.
h must be in the range 0 to 23, m and s must be in the range 0 to 59, and ms must be in the range 0 to 999. Returns true if the set time is valid; otherwise returns false.
See also isValid().
Sets this time to the current time. This is practical for timing:
QTime t; t.start(); some_lengthy_task(); qDebug("Time elapsed: %d ms", t.elapsed());
See also restart(), elapsed(), and currentTime().
Returns the time as a string. The format parameter determines the format of the result string.
These expressions may be used:
Expression | Output |
---|---|
h | the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) |
hh | the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) |
H | the hour without a leading zero (0 to 23, even with AM/PM display) |
HH | the hour with a leading zero (00 to 23, even with AM/PM display) |
m | the minute without a leading zero (0 to 59) |
mm | the minute with a leading zero (00 to 59) |
s | the second whithout a leading zero (0 to 59) |
ss | the second whith a leading zero (00 to 59) |
z | the milliseconds without leading zeroes (0 to 999) |
zzz | the milliseconds with leading zeroes (000 to 999) |
AP or A | use AM/PM display. AP will be replaced by either "AM" or "PM". |
ap or a | use am/pm display. ap will be replaced by either "am" or "pm". |
All other input characters will be ignored. Any sequence of characters that are enclosed in singlequotes will be treated as text and not be used as an expression.
Example format strings (assuming that the QTime is 14:13:09.042)
Format | Result |
---|---|
hh:mm:ss.zzz | 14:13:09.042 |
h:m:s ap | 2:13:9 pm |
H:m:s a | 14:13:9 pm |
If the datetime is invalid, an empty string will be returned.
See also QDate::toString() and QDateTime::toString().
This is an overloaded member function, provided for convenience.
Returns the time as a string. Milliseconds are not included. The f parameter determines the format of the string.
If f is Qt::TextDate, the string format is HH:MM:SS; e.g. 1 second before midnight would be "23:59:59".
If f is Qt::ISODate, the string format corresponds to the ISO 8601 extended specification for representations of dates, which is also HH:MM:SS.
If f is Qt::LocalDate, the string format depends on the locale settings of the system.
If the datetime is invalid, an empty string will be returned.
Returns true if this time is different from t; otherwise returns false.
Returns true if this time is earlier than t; otherwise returns false.
Returns true if this time is earlier than or equal to t; otherwise returns false.
Returns true if this time is equal to t; otherwise returns false.
Returns true if this time is later than t; otherwise returns false.
Returns true if this time is later than or equal to t; otherwise returns false.
This is an overloaded member function, provided for convenience.
Writes time to stream out.
See also Format of the QDataStream operators.
This is an overloaded member function, provided for convenience.
Reads a time from stream in into the given time.
See also Format of the QDataStream operators.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.1 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com