CopperSpice API
1.9.2
|
Stores time information. More...
Public Methods | |
constexpr | QTime () |
QTime (int h, int m, int s=0, int ms=0) | |
QTime | addMSecs (int msecs) const |
QTime | addSecs (int seconds) const |
int | elapsed () const |
int | hour () const |
constexpr bool | isNull () const |
bool | isValid () const |
int | minute () const |
int | msec () const |
int | msecsSinceStartOfDay () const |
int | msecsTo (const QTime &value) const |
bool | operator!= (const QTime &value) const |
bool | operator< (const QTime &value) const |
bool | operator<= (const QTime &value) const |
bool | operator== (const QTime &value) const |
bool | operator> (const QTime &value) const |
bool | operator>= (const QTime &value) const |
int | restart () |
int | second () const |
int | secsTo (const QTime &value) const |
bool | setHMS (int h, int m, int s, int ms=0) |
void | start () |
QString | toString (const QString &format) const |
QString | toString (Qt::DateFormat format=Qt::TextDate) const |
Static Public Methods | |
static QTime | currentTime () |
static QTime | fromMSecsSinceStartOfDay (int msecs) |
static QTime | fromString (const QString &str, const QString &format) |
static QTime | fromString (const QString &str, Qt::DateFormat format=Qt::TextDate) |
static bool | isValid (int h, int m, int s, int ms=0) |
Friends | |
QDataStream & | operator<< (QDataStream &stream, const QTime &time) |
QDataStream & | operator>> (QDataStream &stream, QTime &time) |
class | QDateTime |
The QTime class stores time information which is defined as the number of hours, minutes, seconds, and milliseconds since midnight. This class retrieves the current time from the operating system internal clock. A variety of methods are provided to calculate a time based on some offset or compare two existing times.
A QTime is typically created by specifying the number of hours, minutes, seconds, and milliseconds or using the static method currentTime() which returns a new QTime based on the system clock.
QTime uses a 24 hour clock format and has no concept of AM/PM. This class does not store any information about time zones or daylight saving time (DST).
The hour(), minute(), second(), and msec() methods provide access to the number of hours, minutes, seconds, and milliseconds of the given QTime. The same information is provided in a text format by calling one of the toString() methods.
There are additional methods which can be used to calculate a span of elapsed time using start(), restart(), and elapsed(). The number of seconds or milliseconds between two times can be found using secsTo() or msecsTo().
|
inlineconstexpr |
QTime::QTime | ( | int | h, |
int | m, | ||
int | s = 0 , |
||
int | ms = 0 |
||
) |
Constructs a new QTime with hour h, minute m, seconds s and milliseconds ms. The value for 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.
|
nodiscard |
Adds the given number of msecs milliseconds to the current QTime and returns the result. If msecs is negative the value for msecs is subtracted from this QTime. The value for QTime will wrap if it crosses midnight.
|
nodiscard |
Adds the given number of seconds to the current QTime and returns the result. If seconds is negative the value for seconds is subtracted from this QTime. The value for QTime will wrap if it crosses midnight.
|
static |
Returns the current QTime as reported by the system clock. The accuracy depends on the underlying operating system and not all operating systems provide 1 millisecond accuracy.
int QTime::elapsed | ( | ) | const |
Returns the number of milliseconds which has elapsed since the last time start() or restart() was called. The count is reset to zero every 24 hours. If the system clock is modified while this method is tracking a count, the result will be undefined. A problem can also occur if daylight saving time is turned on or off.
|
inlinestatic |
Returns a new QTime with the time set to the number of milliseconds, msecs since midnight. If msecs falls outside the valid range an invalid QTime will be returned.
Returns the QTime represented by the str using the format given. If the string does not represent a valid time using the given format, then QTime will set to an invalid time.
The following expressions can be used as part of the format. If any other characters are used in the format they will be treated as literal text. Any sequence of characters which are enclosed in single quotes will also be treated as literal text.
Expression | Output |
---|---|
h | Hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) |
hh | Hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) |
m | Minute without a leading zero (0 to 59) |
mm | Minute with a leading zero (00 to 59) |
s | Second without a leading zero (0 to 59) |
ss | Second with a leading zero (00 to 59) |
z | Milliseconds without leading zeroes (0 to 999) |
zzz | Milliseconds with leading zeroes (000 to 999) |
AP | AM/PM time, AP must be either "AM" or "PM". |
ap | AM/PM time, ap must be either "am" or "pm". |
Expressions which do not expect leading zeroes (h, m, s and z) are greedy. This means they will consume two digits even if this produces a number which is outside the range of accepted values. For example, the following string does not mean 00:07:10, because the m will consume two digits, resulting in an invalid time.
Any field which is not represented in the given format will be set to zero.
|
static |
Returns the QTime represented by the str using the format given. If the string does not represent a valid time then QTime will set to an invalid time. This method uses a "C" locale encoded string to convert milliseconds to a float.
int QTime::hour | ( | ) | const |
|
inlineconstexpr |
Returns true if this QTime was default constructed, otherwise returns false. A null time is an invalid time.
bool QTime::isValid | ( | ) | const |
Returns true if the QTime is valid, otherwise returns false. For example, 24:12:30 is not a valid time.
|
static |
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.
int QTime::minute | ( | ) | const |
int QTime::msec | ( | ) | const |
|
inline |
Returns the number of milliseconds since the start of the day, which is 00:00:00.
int QTime::msecsTo | ( | const QTime & | value | ) | const |
Returns the number of milliseconds between this QTime and the given value. If value is earlier than this QTime the number of milliseconds returned is negative.
|
inline |
Returns true if this QTime is different from value, otherwise returns false.
|
inline |
Returns true if this QTime is earlier than value, otherwise returns false.
|
inline |
Returns true if this QTime is earlier than or equal to value, otherwise returns false.
|
inline |
Returns true if this QTime is equal to value, otherwise returns false.
|
inline |
Returns true if this QTime is later than value, otherwise returns false.
|
inline |
Returns true if this QTime is later than or equal to value, otherwise returns false.
int QTime::restart | ( | ) |
Returns the number of milliseconds which has elapsed since the last time start() or restart() was called. The count is reset to zero every 24 hours. If the system clock is modified while this method is tracking a count, the result will be undefined. A problem can also occur if daylight saving time is turned on or off.
Sets this QTime to the current system time.
This method is useful for repeated measurements. Simply call start() to find the first measurement and then restart() for each later measurement.
int QTime::second | ( | ) | const |
int QTime::secsTo | ( | const QTime & | value | ) | const |
Returns the number of seconds between this QTime and the given value. If value is earlier than this QTime the number of seconds returned is negative.
bool QTime::setHMS | ( | int | h, |
int | m, | ||
int | s, | ||
int | ms = 0 |
||
) |
Sets this QTime to hour h, minute m, seconds s and milliseconds ms. Returns true if the set time is valid, otherwise returns false. The value for 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.
void QTime::start | ( | ) |
Returns this QTime as a string. The format determines how the result will be formatted. If the QTime is invalid an empty string will be returned. If format is empty the default format of "hh:mm:" will be is used.
The following expressions can be used as part of the format.
Expression | Output |
---|---|
h | Hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) |
hh | Hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) |
H | Hour without a leading zero (0 to 23, even with AM/PM display) |
HH | Hour with a leading zero (00 to 23, even with AM/PM display) |
m | Minute without a leading zero (0 to 59) |
mm | Minute with a leading zero (00 to 59) |
s | Second without a leading zero (0 to 59) |
ss | Second with a leading zero (00 to 59) |
z | Milliseconds without leading zeroes (0 to 999) |
zzz | Milliseconds with leading zeroes (000 to 999) |
AP or A | AM/PM display, AP will be replaced by either "AM" or "PM". |
ap or a | am/pm display, ap will be replaced by either "am" or "pm". |
t | Timezone, for example "CEST" |
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. Two consecutive singleq uotes ("''") are replaced by a single quote in the output.
These are 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 |
QString QTime::toString | ( | Qt::DateFormat | format = Qt::TextDate | ) | const |
Returns this QTime as a string. The format determines how the result will be formatted. If the QTime is invalid an empty string will be returned.
|
friend |
Writes the given time to the stream. Returns a reference to the stream.
Refer to Serializing Data Types for additional information.
|
friend |
Reads from the stream into the given time. Returns a reference to the stream.
Refer to Serializing Data Types for additional information.