The QTime class provides clock time functions. More...
#include <qdatetime.h>
A QTime object contains a clock time, i.e. a 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 (milli)seconds.
QTime operates with 24-hour clock format; it has no concept of AM/PM. It operates with local time; it does not know anything about time zones or daylight savings time.
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 makes a QTime object which contains the system's clock 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. A 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 (milli)seconds between two times can be found using the secsTo() or msecsTo() functions.
QTime can be used to measure a span of elapsed time using the start(), restart(), and elapsed() functions.
Constructs the time 0 hours, minutes, seconds and milliseconds, i.e. 00:00:00.000 (midnight). This is a valid time.
See also isValid().
Constructs a time with hour h, minute m, seconds s and milliseconds ms.
h must be in the range 0-23, m and s must be in the range 0-59, and ms must be in the range 0-999.
See also isValid().
Returns a QTime object containing a time ms milliseconds later than the time of this object (or earlier if ms is negative).
Note that the time will wrap if it passes midnight. See addSecs() for an example.
See also addSecs() and msecsTo().
Returns a QTime object containing a time nsecs seconds later than the time of this object (or earlier if ms is negative).
Note that the time will wrap if it passes midnight.
Example:
QTime n( 14, 0, 0 ); // n == 14:00:00 QTime t; t = n.addSecs( 70 ); // t == 14:01:10 t = n.addSecs( -70 ); // t == 13:58:50 t = n.addSecs( 10*60*60 + 5 ); // t == 00:00:05 t = n.addSecs( -15*60*60 ); // t == 23:00:00
See also addMSecs(), secsTo() and QDateTime::addSecs().
[static]
Returns the current time, as reported by the system clock.
Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.
Returns the number of milliseconds that have elapsed since the last time start() or restart() was called.
Note that the counter wraps to zero 24 hours after the last call to start() or restart.
Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.
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 e.g. when daylight saving is turned on or off.
See also start() and restart().
Returns the hour part (0..23) of the time.
Returns TRUE if the time is equal to 00:00:00.000. A null time is valid.
See also isValid().
Returns TRUE if the time is valid, or FALSE if the time is invalid. The time 23:30:55.746 is valid, while 24:12:30 is invalid.
See also isNull().
[static]
Returns TRUE if the specified time is valid, otherwise FALSE.
The time is valid if h is in the range 0-23, m and s are in the range 0-59, and ms is in the range 0-999.
Example:
QTime::isValid(21, 10, 30); // returns TRUE QTime::isValid(22, 5, 62); // returns FALSE
Returns the minute part (0..59) of the time.
Returns the millisecond part (0..999) of the time.
Returns the number of milliseconds from this time to t (which is negative if t is earlier than this time).
Since QTime measures time within a day and there are 86400000 milliseconds in a day, the result is between -86400000 and 86400000.
See also secsTo().
Returns TRUE if this time is different from t, or FALSE if they are equal.
Returns TRUE if this time is earlier than t, otherwise FALSE.
Returns TRUE if this time is earlier than or equal to t, otherwise FALSE.
Returns TRUE if this time is equal to t, or FALSE if they are different.
Returns TRUE if this time is later than t, otherwise FALSE.
Returns TRUE if this time is later than or equal to t, otherwise FALSE.
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, then 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 e.g. when daylight saving is turned on or off.
See also start(), elapsed() and currentTime().
Returns the second part (0..59) of the time.
Returns the number of seconds from this time to t (which is negative if t is earlier than this time).
Since QTime measures time within a day and there are 86400 seconds in a day, the result is 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-23, m and s must be in the range 0-59, and ms must be in the range 0-999. Returns TRUE if the set time is valid, otherwise FALSE.
See also isValid().
Sets this time to the current time. This is practical for timing:
QTime t; t.start(); // start clock ... // some lengthy task qDebug( "%d\n", t.elapsed() ); // prints # msecs elapsed
See also restart(), elapsed() and currentTime().
Returns the time of this object in a textual format. Milliseconds are not included. The string format is HH:MM:SS, e.g. 1 second before midnight would be "23:59:59".
Reads a time from the stream.
See also Format of the QDataStream operators
Writes a time to the stream.
See also Format of the QDataStream operators
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.
Copyright İ 2000 Trolltech | Trademarks | Qt version 2.2.1
|