[190] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/tools/qdatetime.cpp:1239 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>QTime Class</title>
|
---|
| 7 | <style type="text/css"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { background: #ffffff; color: black; }
|
---|
| 12 | --></style>
|
---|
| 13 | </head>
|
---|
| 14 | <body>
|
---|
| 15 |
|
---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
| 17 | <tr bgcolor="#E5E5E5">
|
---|
| 18 | <td valign=center>
|
---|
| 19 | <a href="index.html">
|
---|
| 20 | <font color="#004faf">Home</font></a>
|
---|
| 21 | | <a href="classes.html">
|
---|
| 22 | <font color="#004faf">All Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main Classes</font></a>
|
---|
| 25 | | <a href="annotated.html">
|
---|
| 26 | <font color="#004faf">Annotated</font></a>
|
---|
| 27 | | <a href="groups.html">
|
---|
| 28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
| 29 | | <a href="functions.html">
|
---|
| 30 | <font color="#004faf">Functions</font></a>
|
---|
| 31 | </td>
|
---|
| 32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QTime Class Reference</h1>
|
---|
| 33 |
|
---|
| 34 | <p>The QTime class provides clock time functions.
|
---|
| 35 | <a href="#details">More...</a>
|
---|
| 36 | <p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when Qt is built with thread support.</p>
|
---|
| 37 | <p><tt>#include <<a href="qdatetime-h.html">qdatetime.h</a>></tt>
|
---|
| 38 | <p><a href="qtime-members.html">List of all member functions.</a>
|
---|
| 39 | <h2>Public Members</h2>
|
---|
| 40 | <ul>
|
---|
| 41 | <li class=fn><a href="#QTime"><b>QTime</b></a> ()</li>
|
---|
| 42 | <li class=fn><a href="#QTime-2"><b>QTime</b></a> ( int h, int m, int s = 0, int ms = 0 )</li>
|
---|
| 43 | <li class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</li>
|
---|
| 44 | <li class=fn>bool <a href="#isValid"><b>isValid</b></a> () const</li>
|
---|
| 45 | <li class=fn>int <a href="#hour"><b>hour</b></a> () const</li>
|
---|
| 46 | <li class=fn>int <a href="#minute"><b>minute</b></a> () const</li>
|
---|
| 47 | <li class=fn>int <a href="#second"><b>second</b></a> () const</li>
|
---|
| 48 | <li class=fn>int <a href="#msec"><b>msec</b></a> () const</li>
|
---|
| 49 | <li class=fn>QString <a href="#toString-2"><b>toString</b></a> ( Qt::DateFormat f = Qt::TextDate ) const</li>
|
---|
| 50 | <li class=fn>QString <a href="#toString"><b>toString</b></a> ( const QString & format ) const</li>
|
---|
| 51 | <li class=fn>bool <a href="#setHMS"><b>setHMS</b></a> ( int h, int m, int s, int ms = 0 )</li>
|
---|
| 52 | <li class=fn>QTime <a href="#addSecs"><b>addSecs</b></a> ( int nsecs ) const</li>
|
---|
| 53 | <li class=fn>int <a href="#secsTo"><b>secsTo</b></a> ( const QTime & t ) const</li>
|
---|
| 54 | <li class=fn>QTime <a href="#addMSecs"><b>addMSecs</b></a> ( int ms ) const</li>
|
---|
| 55 | <li class=fn>int <a href="#msecsTo"><b>msecsTo</b></a> ( const QTime & t ) const</li>
|
---|
| 56 | <li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const QTime & t ) const</li>
|
---|
| 57 | <li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const QTime & t ) const</li>
|
---|
| 58 | <li class=fn>bool <a href="#operator-lt"><b>operator<</b></a> ( const QTime & t ) const</li>
|
---|
| 59 | <li class=fn>bool <a href="#operator-lt-eq"><b>operator<=</b></a> ( const QTime & t ) const</li>
|
---|
| 60 | <li class=fn>bool <a href="#operator-gt"><b>operator></b></a> ( const QTime & t ) const</li>
|
---|
| 61 | <li class=fn>bool <a href="#operator-gt-eq"><b>operator>=</b></a> ( const QTime & t ) const</li>
|
---|
| 62 | <li class=fn>void <a href="#start"><b>start</b></a> ()</li>
|
---|
| 63 | <li class=fn>int <a href="#restart"><b>restart</b></a> ()</li>
|
---|
| 64 | <li class=fn>int <a href="#elapsed"><b>elapsed</b></a> () const</li>
|
---|
| 65 | </ul>
|
---|
| 66 | <h2>Static Public Members</h2>
|
---|
| 67 | <ul>
|
---|
| 68 | <li class=fn>QTime <a href="#currentTime-2"><b>currentTime</b></a> ()</li>
|
---|
| 69 | <li class=fn>QTime <a href="#currentTime"><b>currentTime</b></a> ( Qt::TimeSpec ts )</li>
|
---|
| 70 | <li class=fn>QTime <a href="#fromString"><b>fromString</b></a> ( const QString & s, Qt::DateFormat f = Qt::TextDate )</li>
|
---|
| 71 | <li class=fn>bool <a href="#isValid-2"><b>isValid</b></a> ( int h, int m, int s, int ms = 0 )</li>
|
---|
| 72 | </ul>
|
---|
| 73 | <h2>Related Functions</h2>
|
---|
| 74 | <ul>
|
---|
| 75 | <li class=fn>QDataStream & <a href="#operator-lt-lt"><b>operator<<</b></a> ( QDataStream & s, const QTime & t )</li>
|
---|
| 76 | <li class=fn>QDataStream & <a href="#operator-gt-gt"><b>operator>></b></a> ( QDataStream & s, QTime & t )</li>
|
---|
| 77 | </ul>
|
---|
| 78 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | <p> The QTime class provides clock time functions.
|
---|
| 83 | <p>
|
---|
| 84 |
|
---|
| 85 | <p> A QTime object contains a clock time, i.e. the number of hours,
|
---|
| 86 | minutes, seconds, and milliseconds since midnight. It can read the
|
---|
| 87 | current time from the system clock and measure a span of elapsed
|
---|
| 88 | time. It provides functions for comparing times and for
|
---|
| 89 | manipulating a time by adding a number of (milli)seconds.
|
---|
| 90 | <p> QTime uses the 24-hour clock format; it has no concept of AM/PM.
|
---|
| 91 | It operates in local time; it knows nothing about time zones or
|
---|
| 92 | daylight savings time.
|
---|
| 93 | <p> A QTime object is typically created either by giving the number of
|
---|
| 94 | hours, minutes, seconds, and milliseconds explicitly, or by using
|
---|
| 95 | the static function <a href="#currentTime">currentTime</a>(), which creates a QTime object
|
---|
| 96 | that contains the system's clock time. Note that the accuracy
|
---|
| 97 | depends on the accuracy of the underlying operating system; not
|
---|
| 98 | all systems provide 1-millisecond accuracy.
|
---|
| 99 | <p> The <a href="#hour">hour</a>(), <a href="#minute">minute</a>(), <a href="#second">second</a>(), and <a href="#msec">msec</a>() functions provide
|
---|
| 100 | access to the number of hours, minutes, seconds, and milliseconds
|
---|
| 101 | of the time. The same information is provided in textual format by
|
---|
| 102 | the <a href="#toString">toString</a>() function.
|
---|
| 103 | <p> QTime provides a full set of operators to compare two QTime
|
---|
| 104 | objects. One time is considered smaller than another if it is
|
---|
| 105 | earlier than the other.
|
---|
| 106 | <p> The time a given number of seconds or milliseconds later than a
|
---|
| 107 | given time can be found using the <a href="#addSecs">addSecs</a>() or <a href="#addMSecs">addMSecs</a>()
|
---|
| 108 | functions. Correspondingly, the number of (milli)seconds between
|
---|
| 109 | two times can be found using the <a href="#secsTo">secsTo</a>() or <a href="#msecsTo">msecsTo</a>() functions.
|
---|
| 110 | <p> QTime can be used to measure a span of elapsed time using the
|
---|
| 111 | <a href="#start">start</a>(), <a href="#restart">restart</a>(), and <a href="#elapsed">elapsed</a>() functions.
|
---|
| 112 | <p> <p>See also <a href="qdate.html">QDate</a>, <a href="qdatetime.html">QDateTime</a>, and <a href="time.html">Time and Date</a>.
|
---|
| 113 |
|
---|
| 114 | <hr><h2>Member Function Documentation</h2>
|
---|
| 115 | <h3 class=fn><a name="QTime"></a>QTime::QTime ()
|
---|
| 116 | </h3>
|
---|
| 117 |
|
---|
| 118 | <p> Constructs the time 0 hours, minutes, seconds and milliseconds,
|
---|
| 119 | i.e. 00:00:00.000 (midnight). This is a valid time.
|
---|
| 120 | <p> <p>See also <a href="#isValid">isValid</a>().
|
---|
| 121 |
|
---|
| 122 | <h3 class=fn><a name="QTime-2"></a>QTime::QTime ( int h, int m, int s = 0, int ms = 0 )
|
---|
| 123 | </h3>
|
---|
| 124 | Constructs a time with hour <em>h</em>, minute <em>m</em>, seconds <em>s</em> and
|
---|
| 125 | milliseconds <em>ms</em>.
|
---|
| 126 | <p> <em>h</em> must be in the range 0..23, <em>m</em> and <em>s</em> must be in the
|
---|
| 127 | range 0..59, and <em>ms</em> must be in the range 0..999.
|
---|
| 128 | <p> <p>See also <a href="#isValid">isValid</a>().
|
---|
| 129 |
|
---|
| 130 | <h3 class=fn><a href="qtime.html">QTime</a> <a name="addMSecs"></a>QTime::addMSecs ( int ms ) const
|
---|
| 131 | </h3>
|
---|
| 132 | Returns a QTime object containing a time <em>ms</em> milliseconds later
|
---|
| 133 | than the time of this object (or earlier if <em>ms</em> is negative).
|
---|
| 134 | <p> Note that the time will wrap if it passes midnight. See <a href="#addSecs">addSecs</a>()
|
---|
| 135 | for an example.
|
---|
| 136 | <p> <p>See also <a href="#addSecs">addSecs</a>() and <a href="#msecsTo">msecsTo</a>().
|
---|
| 137 |
|
---|
| 138 | <h3 class=fn><a href="qtime.html">QTime</a> <a name="addSecs"></a>QTime::addSecs ( int nsecs ) const
|
---|
| 139 | </h3>
|
---|
| 140 | Returns a QTime object containing a time <em>nsecs</em> seconds later
|
---|
| 141 | than the time of this object (or earlier if <em>nsecs</em> is negative).
|
---|
| 142 | <p> Note that the time will wrap if it passes midnight.
|
---|
| 143 | <p> Example:
|
---|
| 144 | <pre>
|
---|
| 145 | QTime n( 14, 0, 0 ); // n == 14:00:00
|
---|
| 146 | QTime t;
|
---|
| 147 | t = n.<a href="#addSecs">addSecs</a>( 70 ); // t == 14:01:10
|
---|
| 148 | t = n.<a href="#addSecs">addSecs</a>( -70 ); // t == 13:58:50
|
---|
| 149 | t = n.<a href="#addSecs">addSecs</a>( 10*60*60 + 5 ); // t == 00:00:05
|
---|
| 150 | t = n.<a href="#addSecs">addSecs</a>( -15*60*60 ); // t == 23:00:00
|
---|
| 151 | </pre>
|
---|
| 152 |
|
---|
| 153 | <p> <p>See also <a href="#addMSecs">addMSecs</a>(), <a href="#secsTo">secsTo</a>(), and <a href="qdatetime.html#addSecs">QDateTime::addSecs</a>().
|
---|
| 154 |
|
---|
| 155 | <h3 class=fn><a href="qtime.html">QTime</a> <a name="currentTime"></a>QTime::currentTime ( <a href="qt.html#TimeSpec-enum">Qt::TimeSpec</a> ts )<tt> [static]</tt>
|
---|
| 156 | </h3>
|
---|
| 157 | Returns the current time as reported by the system clock, for the
|
---|
| 158 | TimeSpec <em>ts</em>. The default TimeSpec is LocalTime.
|
---|
| 159 | <p> Note that the accuracy depends on the accuracy of the underlying
|
---|
| 160 | operating system; not all systems provide 1-millisecond accuracy.
|
---|
| 161 | <p> <p>See also <a href="qt.html#TimeSpec-enum">Qt::TimeSpec</a>.
|
---|
| 162 |
|
---|
| 163 | <p>Examples: <a href="aclock-example.html#x1201">aclock/aclock.cpp</a>, <a href="dclock-example.html#x1104">dclock/dclock.cpp</a>, <a href="tutorial1-12.html#x2398">t12/cannon.cpp</a>, and <a href="tictac-example.html#x40">tictac/tictac.cpp</a>.
|
---|
| 164 | <h3 class=fn><a href="qtime.html">QTime</a> <a name="currentTime-2"></a>QTime::currentTime ()<tt> [static]</tt>
|
---|
| 165 | </h3>
|
---|
| 166 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
| 167 | <p> Returns the current time as reported by the system clock.
|
---|
| 168 | <p> Note that the accuracy depends on the accuracy of the underlying
|
---|
| 169 | operating system; not all systems provide 1-millisecond accuracy.
|
---|
| 170 |
|
---|
| 171 | <h3 class=fn>int <a name="elapsed"></a>QTime::elapsed () const
|
---|
| 172 | </h3>
|
---|
| 173 | Returns the number of milliseconds that have elapsed since the
|
---|
| 174 | last time <a href="#start">start</a>() or <a href="#restart">restart</a>() was called.
|
---|
| 175 | <p> Note that the counter wraps to zero 24 hours after the last call
|
---|
| 176 | to start() or restart.
|
---|
| 177 | <p> Note that the accuracy depends on the accuracy of the underlying
|
---|
| 178 | operating system; not all systems provide 1-millisecond accuracy.
|
---|
| 179 | <p> <b>Warning:</b> If the system's clock setting has been changed since the
|
---|
| 180 | last time start() or restart() was called, the result is
|
---|
| 181 | undefined. This can happen when daylight savings time is turned on
|
---|
| 182 | or off.
|
---|
| 183 | <p> <p>See also <a href="#start">start</a>() and <a href="#restart">restart</a>().
|
---|
| 184 |
|
---|
| 185 | <h3 class=fn><a href="qtime.html">QTime</a> <a name="fromString"></a>QTime::fromString ( const <a href="qstring.html">QString</a> & s, <a href="qt.html#DateFormat-enum">Qt::DateFormat</a> f = Qt::TextDate )<tt> [static]</tt>
|
---|
| 186 | </h3>
|
---|
| 187 | Returns the representation <em>s</em> as a QTime using the format <em>f</em>,
|
---|
| 188 | or an invalid time if this is not possible.
|
---|
| 189 | <p> <b>Warning:</b> Note that <a href="qt.html#DateFormat-enum">Qt::LocalDate</a> cannot be used here.
|
---|
| 190 |
|
---|
| 191 | <h3 class=fn>int <a name="hour"></a>QTime::hour () const
|
---|
| 192 | </h3>
|
---|
| 193 | Returns the hour part (0..23) of the time.
|
---|
| 194 |
|
---|
| 195 | <p>Examples: <a href="aclock-example.html#x1202">aclock/aclock.cpp</a> and <a href="tictac-example.html#x41">tictac/tictac.cpp</a>.
|
---|
| 196 | <h3 class=fn>bool <a name="isNull"></a>QTime::isNull () const
|
---|
| 197 | </h3>
|
---|
| 198 |
|
---|
| 199 | <p> Returns TRUE if the time is equal to 00:00:00.000; otherwise
|
---|
| 200 | returns FALSE. A null time is valid.
|
---|
| 201 | <p> <p>See also <a href="#isValid">isValid</a>().
|
---|
| 202 |
|
---|
| 203 | <h3 class=fn>bool <a name="isValid"></a>QTime::isValid () const
|
---|
| 204 | </h3>
|
---|
| 205 | Returns TRUE if the time is valid; otherwise returns FALSE. The
|
---|
| 206 | time 23:30:55.746 is valid, whereas 24:12:30 is invalid.
|
---|
| 207 | <p> <p>See also <a href="#isNull">isNull</a>().
|
---|
| 208 |
|
---|
| 209 | <h3 class=fn>bool <a name="isValid-2"></a>QTime::isValid ( int h, int m, int s, int ms = 0 )<tt> [static]</tt>
|
---|
| 210 | </h3>
|
---|
| 211 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
| 212 | <p> Returns TRUE if the specified time is valid; otherwise returns
|
---|
| 213 | FALSE.
|
---|
| 214 | <p> The time is valid if <em>h</em> is in the range 0..23, <em>m</em> and <em>s</em> are
|
---|
| 215 | in the range 0..59, and <em>ms</em> is in the range 0..999.
|
---|
| 216 | <p> Example:
|
---|
| 217 | <pre>
|
---|
| 218 | QTime::<a href="#isValid">isValid</a>(21, 10, 30); // returns TRUE
|
---|
| 219 | QTime::<a href="#isValid">isValid</a>(22, 5, 62); // returns FALSE
|
---|
| 220 | </pre>
|
---|
| 221 |
|
---|
| 222 |
|
---|
| 223 | <h3 class=fn>int <a name="minute"></a>QTime::minute () const
|
---|
| 224 | </h3>
|
---|
| 225 | Returns the minute part (0..59) of the time.
|
---|
| 226 |
|
---|
| 227 | <p>Examples: <a href="aclock-example.html#x1203">aclock/aclock.cpp</a> and <a href="tictac-example.html#x42">tictac/tictac.cpp</a>.
|
---|
| 228 | <h3 class=fn>int <a name="msec"></a>QTime::msec () const
|
---|
| 229 | </h3>
|
---|
| 230 | Returns the millisecond part (0..999) of the time.
|
---|
| 231 |
|
---|
| 232 | <h3 class=fn>int <a name="msecsTo"></a>QTime::msecsTo ( const <a href="qtime.html">QTime</a> & t ) const
|
---|
| 233 | </h3>
|
---|
| 234 | Returns the number of milliseconds from this time to <em>t</em> (which
|
---|
| 235 | is negative if <em>t</em> is earlier than this time).
|
---|
| 236 | <p> Because QTime measures time within a day and there are 86400
|
---|
| 237 | seconds in a day, the result is always between -86400000 and
|
---|
| 238 | 86400000 msec.
|
---|
| 239 | <p> <p>See also <a href="#secsTo">secsTo</a>().
|
---|
| 240 |
|
---|
| 241 | <h3 class=fn>bool <a name="operator!-eq"></a>QTime::operator!= ( const <a href="qtime.html">QTime</a> & t ) const
|
---|
| 242 | </h3>
|
---|
| 243 |
|
---|
| 244 | <p> Returns TRUE if this time is different from <em>t</em>; otherwise returns FALSE.
|
---|
| 245 |
|
---|
| 246 | <h3 class=fn>bool <a name="operator-lt"></a>QTime::operator< ( const <a href="qtime.html">QTime</a> & t ) const
|
---|
| 247 | </h3>
|
---|
| 248 |
|
---|
| 249 | <p> Returns TRUE if this time is earlier than <em>t</em>; otherwise returns FALSE.
|
---|
| 250 |
|
---|
| 251 | <h3 class=fn>bool <a name="operator-lt-eq"></a>QTime::operator<= ( const <a href="qtime.html">QTime</a> & t ) const
|
---|
| 252 | </h3>
|
---|
| 253 |
|
---|
| 254 | <p> Returns TRUE if this time is earlier than or equal to <em>t</em>;
|
---|
| 255 | otherwise returns FALSE.
|
---|
| 256 |
|
---|
| 257 | <h3 class=fn>bool <a name="operator-eq-eq"></a>QTime::operator== ( const <a href="qtime.html">QTime</a> & t ) const
|
---|
| 258 | </h3>
|
---|
| 259 |
|
---|
| 260 | <p> Returns TRUE if this time is equal to <em>t</em>; otherwise returns FALSE.
|
---|
| 261 |
|
---|
| 262 | <h3 class=fn>bool <a name="operator-gt"></a>QTime::operator> ( const <a href="qtime.html">QTime</a> & t ) const
|
---|
| 263 | </h3>
|
---|
| 264 |
|
---|
| 265 | <p> Returns TRUE if this time is later than <em>t</em>; otherwise returns FALSE.
|
---|
| 266 |
|
---|
| 267 | <h3 class=fn>bool <a name="operator-gt-eq"></a>QTime::operator>= ( const <a href="qtime.html">QTime</a> & t ) const
|
---|
| 268 | </h3>
|
---|
| 269 |
|
---|
| 270 | <p> Returns TRUE if this time is later than or equal to <em>t</em>;
|
---|
| 271 | otherwise returns FALSE.
|
---|
| 272 |
|
---|
| 273 | <h3 class=fn>int <a name="restart"></a>QTime::restart ()
|
---|
| 274 | </h3>
|
---|
| 275 | Sets this time to the current time and returns the number of
|
---|
| 276 | milliseconds that have elapsed since the last time <a href="#start">start</a>() or
|
---|
| 277 | <a href="#restart">restart</a>() was called.
|
---|
| 278 | <p> This function is guaranteed to be atomic and is thus very handy
|
---|
| 279 | for repeated measurements. Call start() to start the first
|
---|
| 280 | measurement and then restart() for each later measurement.
|
---|
| 281 | <p> Note that the counter wraps to zero 24 hours after the last call
|
---|
| 282 | to start() or restart().
|
---|
| 283 | <p> <b>Warning:</b> If the system's clock setting has been changed since the
|
---|
| 284 | last time start() or restart() was called, the result is
|
---|
| 285 | undefined. This can happen when daylight savings time is turned on
|
---|
| 286 | or off.
|
---|
| 287 | <p> <p>See also <a href="#start">start</a>(), <a href="#elapsed">elapsed</a>(), and <a href="#currentTime">currentTime</a>().
|
---|
| 288 |
|
---|
| 289 | <h3 class=fn>int <a name="second"></a>QTime::second () const
|
---|
| 290 | </h3>
|
---|
| 291 | Returns the second part (0..59) of the time.
|
---|
| 292 |
|
---|
| 293 | <p>Example: <a href="tictac-example.html#x43">tictac/tictac.cpp</a>.
|
---|
| 294 | <h3 class=fn>int <a name="secsTo"></a>QTime::secsTo ( const <a href="qtime.html">QTime</a> & t ) const
|
---|
| 295 | </h3>
|
---|
| 296 | Returns the number of seconds from this time to <em>t</em> (which is
|
---|
| 297 | negative if <em>t</em> is earlier than this time).
|
---|
| 298 | <p> Because QTime measures time within a day and there are 86400
|
---|
| 299 | seconds in a day, the result is always between -86400 and 86400.
|
---|
| 300 | <p> <p>See also <a href="#addSecs">addSecs</a>() and <a href="qdatetime.html#secsTo">QDateTime::secsTo</a>().
|
---|
| 301 |
|
---|
| 302 | <p>Example: <a href="tutorial1-12.html#x2399">t12/cannon.cpp</a>.
|
---|
| 303 | <h3 class=fn>bool <a name="setHMS"></a>QTime::setHMS ( int h, int m, int s, int ms = 0 )
|
---|
| 304 | </h3>
|
---|
| 305 | Sets the time to hour <em>h</em>, minute <em>m</em>, seconds <em>s</em> and
|
---|
| 306 | milliseconds <em>ms</em>.
|
---|
| 307 | <p> <em>h</em> must be in the range 0..23, <em>m</em> and <em>s</em> must be in the
|
---|
| 308 | range 0..59, and <em>ms</em> must be in the range 0..999. Returns TRUE
|
---|
| 309 | if the set time is valid; otherwise returns FALSE.
|
---|
| 310 | <p> <p>See also <a href="#isValid">isValid</a>().
|
---|
| 311 |
|
---|
| 312 | <h3 class=fn>void <a name="start"></a>QTime::start ()
|
---|
| 313 | </h3>
|
---|
| 314 | Sets this time to the current time. This is practical for timing:
|
---|
| 315 | <p> <pre>
|
---|
| 316 | QTime t;
|
---|
| 317 | t.<a href="#start">start</a>();
|
---|
| 318 | some_lengthy_task();
|
---|
| 319 | <a href="qapplication.html#qDebug">qDebug</a>( "Time elapsed: %d ms", t.<a href="#elapsed">elapsed</a>() );
|
---|
| 320 | </pre>
|
---|
| 321 |
|
---|
| 322 | <p> <p>See also <a href="#restart">restart</a>(), <a href="#elapsed">elapsed</a>(), and <a href="#currentTime">currentTime</a>().
|
---|
| 323 |
|
---|
| 324 | <h3 class=fn><a href="qstring.html">QString</a> <a name="toString"></a>QTime::toString ( const <a href="qstring.html">QString</a> & format ) const
|
---|
| 325 | </h3>
|
---|
| 326 | Returns the time as a string. The <em>format</em> parameter determines
|
---|
| 327 | the format of the result string.
|
---|
| 328 | <p> These expressions may be used:
|
---|
| 329 | <p> <center><table cellpadding="4" cellspacing="2" border="0">
|
---|
| 330 | <tr bgcolor="#a2c511"> <th valign="top">Expression <th valign="top">Output
|
---|
| 331 | <tr bgcolor="#f0f0f0"> <td valign="top">h
|
---|
| 332 | <td valign="top">the hour without a leading zero (0..23 or 1..12 if AM/PM display)
|
---|
| 333 | <tr bgcolor="#d0d0d0"> <td valign="top">hh
|
---|
| 334 | <td valign="top">the hour with a leading zero (00..23 or 01..12 if AM/PM display)
|
---|
| 335 | <tr bgcolor="#f0f0f0"> <td valign="top">m <td valign="top">the minute without a leading zero (0..59)
|
---|
| 336 | <tr bgcolor="#d0d0d0"> <td valign="top">mm <td valign="top">the minute with a leading zero (00..59)
|
---|
| 337 | <tr bgcolor="#f0f0f0"> <td valign="top">s <td valign="top">the second whithout a leading zero (0..59)
|
---|
| 338 | <tr bgcolor="#d0d0d0"> <td valign="top">ss <td valign="top">the second whith a leading zero (00..59)
|
---|
| 339 | <tr bgcolor="#f0f0f0"> <td valign="top">z <td valign="top">the milliseconds without leading zeroes (0..999)
|
---|
| 340 | <tr bgcolor="#d0d0d0"> <td valign="top">zzz <td valign="top">the milliseconds with leading zeroes (000..999)
|
---|
| 341 | <tr bgcolor="#f0f0f0"> <td valign="top">AP
|
---|
| 342 | <td valign="top">use AM/PM display. <em>AP</em> will be replaced by either "AM" or "PM".
|
---|
| 343 | <tr bgcolor="#d0d0d0"> <td valign="top">ap
|
---|
| 344 | <td valign="top">use am/pm display. <em>ap</em> will be replaced by either "am" or "pm".
|
---|
| 345 | </table></center>
|
---|
| 346 | <p> All other input characters will be ignored.
|
---|
| 347 | <p> Example format strings (assuming that the QTime is 14:13:09.042)
|
---|
| 348 | <p> <center><table cellpadding="4" cellspacing="2" border="0">
|
---|
| 349 | <tr bgcolor="#a2c511"> <th valign="top">Format <th valign="top">Result
|
---|
| 350 | <tr bgcolor="#f0f0f0"> <td valign="top">hh:mm:ss.zzz <td valign="top" colspan="1" rowspan="1"> 14:13:09.042
|
---|
| 351 | <tr bgcolor="#d0d0d0"> <td valign="top">h:m:s ap <td valign="top" colspan="1" rowspan="1"> 2:13:9 pm
|
---|
| 352 | </table></center>
|
---|
| 353 | <p> If the time is an invalid time, then <a href="qstring.html#QString-null">QString::null</a> will be returned.
|
---|
| 354 | <p> <p>See also <a href="qdate.html#toString">QDate::toString</a>() and <a href="qdatetime.html#toString">QDateTime::toString</a>().
|
---|
| 355 |
|
---|
| 356 | <h3 class=fn><a href="qstring.html">QString</a> <a name="toString-2"></a>QTime::toString ( <a href="qt.html#DateFormat-enum">Qt::DateFormat</a> f = Qt::TextDate ) const
|
---|
| 357 | </h3>
|
---|
| 358 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
| 359 | <p> Returns the time as a string. Milliseconds are not included. The
|
---|
| 360 | <em>f</em> parameter determines the format of the string.
|
---|
| 361 | <p> If <em>f</em> is <a href="qt.html#DateFormat-enum">Qt::TextDate</a>, the string format is HH:MM:SS; e.g. 1
|
---|
| 362 | second before midnight would be "23:59:59".
|
---|
| 363 | <p> If <em>f</em> is <a href="qt.html#DateFormat-enum">Qt::ISODate</a>, the string format corresponds to the
|
---|
| 364 | ISO 8601 extended specification for representations of dates,
|
---|
| 365 | which is also HH:MM:SS.
|
---|
| 366 | <p> If <em>f</em> is Qt::LocalDate, the string format depends on the locale
|
---|
| 367 | settings of the system.
|
---|
| 368 | <p> If the time is an invalid time, then <a href="qstring.html#QString-null">QString::null</a> will be returned.
|
---|
| 369 |
|
---|
| 370 | <hr><h2>Related Functions</h2>
|
---|
| 371 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt"></a>operator<< ( <a href="qdatastream.html">QDataStream</a> & s, const <a href="qtime.html">QTime</a> & t )
|
---|
| 372 | </h3>
|
---|
| 373 |
|
---|
| 374 | <p> Writes time <em>t</em> to the stream <em>s</em>.
|
---|
| 375 | <p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.
|
---|
| 376 |
|
---|
| 377 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt"></a>operator>> ( <a href="qdatastream.html">QDataStream</a> & s, <a href="qtime.html">QTime</a> & t )
|
---|
| 378 | </h3>
|
---|
| 379 |
|
---|
| 380 | <p> Reads a time from the stream <em>s</em> into <em>t</em>.
|
---|
| 381 | <p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.
|
---|
| 382 |
|
---|
| 383 | <!-- eof -->
|
---|
| 384 | <hr><p>
|
---|
| 385 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
| 386 | Copyright © 1995-2007
|
---|
| 387 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
| 388 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 389 | <td>Copyright © 2007
|
---|
| 390 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 391 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 392 | </table></div></address></body>
|
---|
| 393 | </html>
|
---|