Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The TQTime class provides clock time functions. More...
All the functions in this class are reentrant when TQt is built with thread support.
#include <qdatetime.h>
The TQTime class provides clock time functions.
A TQTime 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 (milli)seconds.
TQTime uses the 24-hour clock format; it has no concept of AM/PM. It operates in local time; it knows nothing about time zones or daylight savings time.
A TQTime 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 TQTime object that 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.
TQTime provides a full set of operators to compare two TQTime 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 (milli)seconds between two times can be found using the secsTo() or msecsTo() functions.
TQTime can be used to measure a span of elapsed time using the start(), restart(), and elapsed() functions.
See also TQDate, TQDateTime, and Time and Date.
Constructs the time 0 hours, minutes, seconds and milliseconds, i.e. 00:00:00.000 (midnight). This is a valid time.
See also isValid().
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().
Note that the time will wrap if it passes midnight. See addSecs() for an example.
See also addSecs() and msecsTo().
Note that the time will wrap if it passes midnight.
Example:
TQTime n( 14, 0, 0 ); // n == 14:00:00 TQTime 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 TQDateTime::addSecs().
Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.
See also TQt::TimeSpec.
Examples: aclock/aclock.cpp, dclock/dclock.cpp, t12/cannon.cpp, and tictac/tictac.cpp.
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.
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 when daylight savings time is turned on or off.
See also start() and restart().
Warning: Note that TQt::LocalDate cannot be used here.
Examples: aclock/aclock.cpp and tictac/tictac.cpp.
Returns TRUE if the time is equal to 00:00:00.000; otherwise returns FALSE. A null time is valid.
See also isValid().
See also isNull().
Returns TRUE if the specified time is valid; otherwise returns 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:
TQTime::isValid(21, 10, 30); // returns TRUE TQTime::isValid(22, 5, 62); // returns FALSE
Examples: aclock/aclock.cpp and tictac/tictac.cpp.
Because TQTime 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().
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 function is guaranteed to be atomic and is thus very handy for repeated measurements. Call start() to start the first measurement and 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 when daylight savings time is turned on or off.
See also start(), elapsed(), and currentTime().
Example: tictac/tictac.cpp.
Because TQTime 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 TQDateTime::secsTo().
Example: t12/cannon.cpp.
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 returns FALSE.
See also isValid().
TQTime t; t.start(); some_lengthy_task(); qDebug( "Time elapsed: %d ms", t.elapsed() );
See also restart(), elapsed(), and currentTime().
These expressions may be used:
Expression | Output |
---|---|
h | the hour without a leading zero (0..23 or 1..12 if AM/PM display) |
hh | the hour with a leading zero (00..23 or 01..12 if AM/PM display) |
m | the minute without a leading zero (0..59) |
mm | the minute with a leading zero (00..59) |
s | the second whithout a leading zero (0..59) |
ss | the second whith a leading zero (00..59) |
z | the milliseconds without leading zeroes (0..999) |
zzz | the milliseconds with leading zeroes (000..999) |
AP | use AM/PM display. AP will be replaced by either "AM" or "PM". |
ap | use am/pm display. ap will be replaced by either "am" or "pm". |
All other input characters will be ignored.
Example format strings (assuming that the TQTime is 14:13:09.042)
Format | Result |
---|---|
hh:mm:ss.zzz | 14:13:09.042 |
h:m:s ap | 2:13:9 pm |
If the time is an invalid time, then TQString::null will be returned.
See also TQDate::toString() and TQDateTime::toString().
Returns the time as a string. Milliseconds are not included. The f parameter determines the format of the string.
If f is TQt::TextDate, the string format is HH:MM:SS; e.g. 1 second before midnight would be "23:59:59".
If f is TQt::ISODate, the string format corresponds to the ISO 8601 extended specification for representations of dates, which is also HH:MM:SS.
If f is TQt::LocalDate, the string format depends on the locale settings of the system.
If the time is an invalid time, then TQString::null will be returned.
Writes time t to the stream s.
See also Format of the TQDataStream operators.
Reads a time from the stream s into t.
See also Format of the TQDataStream operators.
This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.
Copyright © 2007 Trolltech | Trademarks | TQt 3.3.8
|