1QTime(3qt) QTime(3qt)
2
3
4
6 QTime - Clock time functions
7
9 All the functions in this class are reentrant when Qt is built with
10 thread support.</p>
11
12 #include <qdatetime.h>
13
14 Public Members
15 QTime ()
16 QTime ( int h, int m, int s = 0, int ms = 0 )
17 bool isNull () const
18 bool isValid () const
19 int hour () const
20 int minute () const
21 int second () const
22 int msec () const
23 QString toString ( Qt::DateFormat f = Qt::TextDate ) const
24 QString toString ( const QString & format ) const
25 bool setHMS ( int h, int m, int s, int ms = 0 )
26 QTime addSecs ( int nsecs ) const
27 int secsTo ( const QTime & t ) const
28 QTime addMSecs ( int ms ) const
29 int msecsTo ( const QTime & t ) const
30 bool operator== ( const QTime & t ) const
31 bool operator!= ( const QTime & t ) const
32 bool operator< ( const QTime & t ) const
33 bool operator<= ( const QTime & t ) const
34 bool operator> ( const QTime & t ) const
35 bool operator>= ( const QTime & t ) const
36 void start ()
37 int restart ()
38 int elapsed () const
39
40 Static Public Members
41 QTime currentTime ()
42 QTime currentTime ( Qt::TimeSpec ts )
43 QTime fromString ( const QString & s, Qt::DateFormat f = Qt::TextDate )
44 bool isValid ( int h, int m, int s, int ms = 0 )
45
47 QDataStream & operator<< ( QDataStream & s, const QTime & t )
48 QDataStream & operator>> ( QDataStream & s, QTime & t )
49
51 The QTime class provides clock time functions.
52
53 A QTime object contains a clock time, i.e. the number of hours,
54 minutes, seconds, and milliseconds since midnight. It can read the
55 current time from the system clock and measure a span of elapsed time.
56 It provides functions for comparing times and for manipulating a time
57 by adding a number of (milli)seconds.
58
59 QTime uses the 24-hour clock format; it has no concept of AM/PM. It
60 operates in local time; it knows nothing about time zones or daylight
61 savings time.
62
63 A QTime object is typically created either by giving the number of
64 hours, minutes, seconds, and milliseconds explicitly, or by using the
65 static function currentTime(), which creates a QTime object that
66 contains the system's clock time. Note that the accuracy depends on the
67 accuracy of the underlying operating system; not all systems provide
68 1-millisecond accuracy.
69
70 The hour(), minute(), second(), and msec() functions provide access to
71 the number of hours, minutes, seconds, and milliseconds of the time.
72 The same information is provided in textual format by the toString()
73 function.
74
75 QTime provides a full set of operators to compare two QTime objects.
76 One time is considered smaller than another if it is earlier than the
77 other.
78
79 The time a given number of seconds or milliseconds later than a given
80 time can be found using the addSecs() or addMSecs() functions.
81 Correspondingly, the number of (milli)seconds between two times can be
82 found using the secsTo() or msecsTo() functions.
83
84 QTime can be used to measure a span of elapsed time using the start(),
85 restart(), and elapsed() functions.
86
87 See also QDate, QDateTime, and Time and Date.
88
91 Constructs the time 0 hours, minutes, seconds and milliseconds, i.e.
92 00:00:00.000 (midnight). This is a valid time.
93
94 See also isValid().
95
97 Constructs a time with hour h, minute m, seconds s and milliseconds ms.
98
99 h must be in the range 0..23, m and s must be in the range 0..59, and
100 ms must be in the range 0..999.
101
102 See also isValid().
103
105 Returns a QTime object containing a time ms milliseconds later than the
106 time of this object (or earlier if ms is negative).
107
108 Note that the time will wrap if it passes midnight. See addSecs() for
109 an example.
110
111 See also addSecs() and msecsTo().
112
114 Returns a QTime object containing a time nsecs seconds later than the
115 time of this object (or earlier if nsecs is negative).
116
117 Note that the time will wrap if it passes midnight.
118
119 Example:
120
121 QTime n( 14, 0, 0 ); // n == 14:00:00
122 QTime t;
123 t = n.addSecs( 70 ); // t == 14:01:10
124 t = n.addSecs( -70 ); // t == 13:58:50
125 t = n.addSecs( 10*60*60 + 5 ); // t == 00:00:05
126 t = n.addSecs( -15*60*60 ); // t == 23:00:00
127
128 See also addMSecs(), secsTo(), and QDateTime::addSecs().
129
131 Returns the current time as reported by the system clock, for the
132 TimeSpec ts. The default TimeSpec is LocalTime.
133
134 Note that the accuracy depends on the accuracy of the underlying
135 operating system; not all systems provide 1-millisecond accuracy.
136
137 See also Qt::TimeSpec.
138
139 Examples:
140
142 This is an overloaded member function, provided for convenience. It
143 behaves essentially like the above function.
144
145 Returns the current time as reported by the system clock.
146
147 Note that the accuracy depends on the accuracy of the underlying
148 operating system; not all systems provide 1-millisecond accuracy.
149
151 Returns the number of milliseconds that have elapsed since the last
152 time start() or restart() was called.
153
154 Note that the counter wraps to zero 24 hours after the last call to
155 start() or restart.
156
157 Note that the accuracy depends on the accuracy of the underlying
158 operating system; not all systems provide 1-millisecond accuracy.
159
160 Warning: If the system's clock setting has been changed since the last
161 time start() or restart() was called, the result is undefined. This can
162 happen when daylight savings time is turned on or off.
163
164 See also start() and restart().
165
167 [static]
168 Returns the representation s as a QTime using the format f, or an
169 invalid time if this is not possible.
170
171 Warning: Note that Qt::LocalDate cannot be used here.
172
174 Returns the hour part (0..23) of the time.
175
176 Examples:
177
179 Returns TRUE if the time is equal to 00:00:00.000; otherwise returns
180 FALSE. A null time is valid.
181
182 See also isValid().
183
185 Returns TRUE if the time is valid; otherwise returns FALSE. The time
186 23:30:55.746 is valid, whereas 24:12:30 is invalid.
187
188 See also isNull().
189
191 This is an overloaded member function, provided for convenience. It
192 behaves essentially like the above function.
193
194 Returns TRUE if the specified time is valid; otherwise returns FALSE.
195
196 The time is valid if h is in the range 0..23, m and s are in the range
197 0..59, and ms is in the range 0..999.
198
199 Example:
200
201 QTime::isValid(21, 10, 30); // returns TRUE
202 QTime::isValid(22, 5, 62); // returns FALSE
203
205 Returns the minute part (0..59) of the time.
206
207 Examples:
208
210 Returns the millisecond part (0..999) of the time.
211
213 Returns the number of milliseconds from this time to t (which is
214 negative if t is earlier than this time).
215
216 Because QTime measures time within a day and there are 86400 seconds in
217 a day, the result is always between -86400000 and 86400000 msec.
218
219 See also secsTo().
220
222 Returns TRUE if this time is different from t; otherwise returns FALSE.
223
225 Returns TRUE if this time is earlier than t; otherwise returns FALSE.
226
228 Returns TRUE if this time is earlier than or equal to t; otherwise
229 returns FALSE.
230
232 Returns TRUE if this time is equal to t; otherwise returns FALSE.
233
235 Returns TRUE if this time is later than t; otherwise returns FALSE.
236
238 Returns TRUE if this time is later than or equal to t; otherwise
239 returns FALSE.
240
242 Sets this time to the current time and returns the number of
243 milliseconds that have elapsed since the last time start() or restart()
244 was called.
245
246 This function is guaranteed to be atomic and is thus very handy for
247 repeated measurements. Call start() to start the first measurement and
248 then restart() for each later measurement.
249
250 Note that the counter wraps to zero 24 hours after the last call to
251 start() or restart().
252
253 Warning: If the system's clock setting has been changed since the last
254 time start() or restart() was called, the result is undefined. This can
255 happen when daylight savings time is turned on or off.
256
257 See also start(), elapsed(), and currentTime().
258
260 Returns the second part (0..59) of the time.
261
262 Example: tictac/tictac.cpp.
263
265 Returns the number of seconds from this time to t (which is negative if
266 t is earlier than this time).
267
268 Because QTime measures time within a day and there are 86400 seconds in
269 a day, the result is always between -86400 and 86400.
270
271 See also addSecs() and QDateTime::secsTo().
272
273 Example: t12/cannon.cpp.
274
276 Sets the time to hour h, minute m, seconds s and milliseconds ms.
277
278 h must be in the range 0..23, m and s must be in the range 0..59, and
279 ms must be in the range 0..999. Returns TRUE if the set time is valid;
280 otherwise returns FALSE.
281
282 See also isValid().
283
285 Sets this time to the current time. This is practical for timing:
286
287 QTime t;
288 t.start();
289 some_lengthy_task();
290 qDebug( "Time elapsed: %d ms", t.elapsed() );
291
292 See also restart(), elapsed(), and currentTime().
293
295 Returns the time as a string. The format parameter determines the
296 format of the result string.
297
298 These expressions may be used:
299
300 <center>.nf
301
302 </center>
303
304 All other input characters will be ignored.
305
306 Example format strings (assuming that the QTime is 14:13:09.042)
307
308 <center>.nf
309
310 </center>
311
312 If the time is an invalid time, then QString::null will be returned.
313
314 See also QDate::toString() and QDateTime::toString().
315
317 This is an overloaded member function, provided for convenience. It
318 behaves essentially like the above function.
319
320 Returns the time as a string. Milliseconds are not included. The f
321 parameter determines the format of the string.
322
323 If f is Qt::TextDate, the string format is HH:MM:SS; e.g. 1 second
324 before midnight would be "23:59:59".
325
326 If f is Qt::ISODate, the string format corresponds to the ISO 8601
327 extended specification for representations of dates, which is also
328 HH:MM:SS.
329
330 If f is Qt::LocalDate, the string format depends on the locale settings
331 of the system.
332
333 If the time is an invalid time, then QString::null will be returned.
334
337 Writes time t to the stream s.
338
339 See also Format of the QDataStream operators.
340
342 Reads a time from the stream s into t.
343
344 See also Format of the QDataStream operators.
345
346
348 http://doc.trolltech.com/qtime.html
349 http://www.trolltech.com/faq/tech.html
350
352 Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
353 license file included in the distribution for a complete license
354 statement.
355
357 Generated automatically from the source code.
358
360 If you find a bug in Qt, please report it as described in
361 http://doc.trolltech.com/bughowto.html. Good bug reports help us to
362 help you. Thank you.
363
364 The definitive Qt documentation is provided in HTML format; it is
365 located at $QTDIR/doc/html and can be read using Qt Assistant or with a
366 web browser. This man page is provided as a convenience for those users
367 who prefer man pages, although this format is not officially supported
368 by Trolltech.
369
370 If you find errors in this manual page, please report them to qt-
371 bugs@trolltech.com. Please include the name of the manual page
372 (qtime.3qt) and the Qt version (3.3.8).
373
374
375
376Trolltech AS 2 February 2007 QTime(3qt)