A QTime object contains a clock time, i.e. the number of hours, minutes, seconds, and milliseconds since midnight. It can read the current time from the system clock and measure a span of elapsed time. It provides functions for comparing times and for manipulating a time by adding a number of milliseconds.
QTime uses the 24-hour clock format; it has no concept of AM/PM. Unlike QDateTime, QTime knows nothing about time zones or daylight savings time (DST).
A QTime object is typically created either by giving the number of hours, minutes, seconds, and milliseconds explicitly, or by using the static function currentTime(), which creates a QTime object that contains the system's local time. Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.
The hour(), minute(), second(), and msec() functions provide access to the number of hours, minutes, seconds, and milliseconds of the time. The same information is provided in textual format by the toString() function.
QTime provides a full set of operators to compare two QTime objects. One time is considered smaller than another if it is earlier than the other.
The time a given number of seconds or milliseconds later than a given time can be found using the addSecs() or addMSecs() functions. Correspondingly, the number of seconds or milliseconds between two times can be found using secsTo() or msecsTo().
QTime can be used to measure a span of elapsed time using the start(), restart(), and elapsed() functions.
Definition at line 115 of file qdatetime.h.
Public Member Functions | |
QTime | addMSecs (int ms) const |
QTime | addSecs (int secs) const |
int | elapsed () const |
int | hour () const |
bool | isNull () const |
bool | isValid () const |
int | minute () const |
int | msec () const |
int | msecsTo (const QTime &) const |
bool | operator!= (const QTime &other) const |
bool | operator< (const QTime &other) const |
bool | operator<= (const QTime &other) const |
bool | operator== (const QTime &other) const |
bool | operator> (const QTime &other) const |
bool | operator>= (const QTime &other) const |
QTime (int h, int m, int s=0, int ms=0) | |
QTime () | |
int | restart () |
int | second () const |
int | secsTo (const QTime &) const |
bool | setHMS (int h, int m, int s, int ms=0) |
void | start () |
QString | toString (const QString &format) const |
QString | toString (Qt::DateFormat f=Qt::TextDate) const |
Static Public Member Functions | |
static QTime | currentTime () |
static QTime | fromString (const QString &s, const QString &format) |
static QTime | fromString (const QString &s, Qt::DateFormat f=Qt::TextDate) |
static bool | isValid (int h, int m, int s, int ms=0) |
Private Types | |
enum | TimeFlag { NullTime = -1 } |
Private Member Functions | |
int | ds () const |
Private Attributes | |
int | mds |
Friends | |
Q_CORE_EXPORT QDataStream & | operator<< (QDataStream &, const QTime &) |
Q_CORE_EXPORT QDataStream & | operator>> (QDataStream &, QTime &) |
class | QDateTime |
class | QDateTimePrivate |