summaryrefslogtreecommitdiffstats
path: root/doc/html/qdatetime.html
blob: 8e96b03e72564eee7c71dc6bdf7d9e3858d7edd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/tools/qdatetime.cpp:1861 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QDateTime Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QDateTime Class Reference</h1>

<p>The QDateTime class provides date and time functions.
<a href="#details">More...</a>
<p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when Qt is built with thread support.</p>
<p><tt>#include &lt;<a href="qdatetime-h.html">qdatetime.h</a>&gt;</tt>
<p><a href="qdatetime-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#QDateTime"><b>QDateTime</b></a> ()</li>
<li class=fn><a href="#QDateTime-2"><b>QDateTime</b></a> ( const&nbsp;QDate&nbsp;&amp;&nbsp;date )</li>
<li class=fn><a href="#QDateTime-3"><b>QDateTime</b></a> ( const&nbsp;QDate&nbsp;&amp;&nbsp;date, const&nbsp;QTime&nbsp;&amp;&nbsp;time )</li>
<li class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</li>
<li class=fn>bool <a href="#isValid"><b>isValid</b></a> () const</li>
<li class=fn>QDate <a href="#date"><b>date</b></a> () const</li>
<li class=fn>QTime <a href="#time"><b>time</b></a> () const</li>
<li class=fn>uint <a href="#toTime_t"><b>toTime_t</b></a> () const</li>
<li class=fn>void <a href="#setDate"><b>setDate</b></a> ( const&nbsp;QDate&nbsp;&amp;&nbsp;date )</li>
<li class=fn>void <a href="#setTime"><b>setTime</b></a> ( const&nbsp;QTime&nbsp;&amp;&nbsp;time )</li>
<li class=fn>void <a href="#setTime_t-2"><b>setTime_t</b></a> ( uint&nbsp;secsSince1Jan1970UTC )</li>
<li class=fn>void <a href="#setTime_t"><b>setTime_t</b></a> ( uint&nbsp;secsSince1Jan1970UTC, Qt::TimeSpec&nbsp;ts )</li>
<li class=fn>QString <a href="#toString-2"><b>toString</b></a> ( Qt::DateFormat&nbsp;f = Qt::TextDate ) const</li>
<li class=fn>QString <a href="#toString"><b>toString</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;format ) const</li>
<li class=fn>QDateTime <a href="#addDays"><b>addDays</b></a> ( int&nbsp;ndays ) const</li>
<li class=fn>QDateTime <a href="#addMonths"><b>addMonths</b></a> ( int&nbsp;nmonths ) const</li>
<li class=fn>QDateTime <a href="#addYears"><b>addYears</b></a> ( int&nbsp;nyears ) const</li>
<li class=fn>QDateTime <a href="#addSecs"><b>addSecs</b></a> ( int&nbsp;nsecs ) const</li>
<li class=fn>int <a href="#daysTo"><b>daysTo</b></a> ( const&nbsp;QDateTime&nbsp;&amp;&nbsp;dt ) const</li>
<li class=fn>int <a href="#secsTo"><b>secsTo</b></a> ( const&nbsp;QDateTime&nbsp;&amp;&nbsp;dt ) const</li>
<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;QDateTime&nbsp;&amp;&nbsp;dt ) const</li>
<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const&nbsp;QDateTime&nbsp;&amp;&nbsp;dt ) const</li>
<li class=fn>bool <a href="#operator-lt"><b>operator&lt;</b></a> ( const&nbsp;QDateTime&nbsp;&amp;&nbsp;dt ) const</li>
<li class=fn>bool <a href="#operator-lt-eq"><b>operator&lt;=</b></a> ( const&nbsp;QDateTime&nbsp;&amp;&nbsp;dt ) const</li>
<li class=fn>bool <a href="#operator-gt"><b>operator&gt;</b></a> ( const&nbsp;QDateTime&nbsp;&amp;&nbsp;dt ) const</li>
<li class=fn>bool <a href="#operator-gt-eq"><b>operator&gt;=</b></a> ( const&nbsp;QDateTime&nbsp;&amp;&nbsp;dt ) const</li>
</ul>
<h2>Static Public Members</h2>
<ul>
<li class=fn>QDateTime <a href="#currentDateTime-2"><b>currentDateTime</b></a> ()</li>
<li class=fn>QDateTime <a href="#currentDateTime"><b>currentDateTime</b></a> ( Qt::TimeSpec&nbsp;ts )</li>
<li class=fn>QDateTime <a href="#fromString"><b>fromString</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;s, Qt::DateFormat&nbsp;f = Qt::TextDate )</li>
</ul>
<h2>Related Functions</h2>
<ul>
<li class=fn>QDataStream &amp; <a href="#operator-lt-lt"><b>operator&lt;&lt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, const&nbsp;QDateTime&nbsp;&amp;&nbsp;dt )</li>
<li class=fn>QDataStream &amp; <a href="#operator-gt-gt"><b>operator&gt;&gt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, QDateTime&nbsp;&amp;&nbsp;dt )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>



The QDateTime class provides date and time functions.
<p> 

<p> A QDateTime object contains a calendar date and a clock time (a
"datetime"). It is a combination of the <a href="qdate.html">QDate</a> and <a href="qtime.html">QTime</a> classes.
It can read the current datetime from the system clock. It
provides functions for comparing datetimes and for manipulating a
datetime by adding a number of seconds, days, months or years.
<p> A QDateTime object is typically created either by giving a date
and time explicitly in the constructor, or by using the static
function <a href="#currentDateTime">currentDateTime</a>(), which returns a QDateTime object set
to the system clock's time. The date and time can be changed with
<a href="#setDate">setDate</a>() and <a href="#setTime">setTime</a>(). A datetime can also be set using the
<a href="#setTime_t">setTime_t</a>() function, which takes a POSIX-standard "number of
seconds since 00:00:00 on January 1, 1970" value. The <a href="#fromString">fromString</a>()
function returns a QDateTime given a string and a date format
which is used to interpret the date within the string.
<p> The <a href="#date">date</a>() and <a href="#time">time</a>() functions provide access to the date and
time parts of the datetime. The same information is provided in
textual format by the <a href="#toString">toString</a>() function.
<p> QDateTime provides a full set of operators to compare two
QDateTime objects where smaller means earlier and larger means
later.
<p> You can increment (or decrement) a datetime by a given number of
seconds using <a href="#addSecs">addSecs</a>() or days using <a href="#addDays">addDays</a>(). Similarly you can
use <a href="#addMonths">addMonths</a>() and <a href="#addYears">addYears</a>(). The <a href="#daysTo">daysTo</a>() function returns the
number of days between two datetimes, and <a href="#secsTo">secsTo</a>() returns the
number of seconds between two datetimes.
<p> The range of a datetime object is constrained to the ranges of the
<a href="qdate.html">QDate</a> and <a href="qtime.html">QTime</a> objects which it embodies.
<p> <p>See also <a href="qdate.html">QDate</a>, <a href="qtime.html">QTime</a>, <a href="qdatetimeedit.html">QDateTimeEdit</a>, and <a href="time.html">Time and Date</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QDateTime"></a>QDateTime::QDateTime ()
</h3>

<p> Constructs a null datetime (i.e. null date and null time). A null
datetime is invalid, since the date is invalid.
<p> <p>See also <a href="#isValid">isValid</a>().

<h3 class=fn><a name="QDateTime-2"></a>QDateTime::QDateTime ( const&nbsp;<a href="qdate.html">QDate</a>&nbsp;&amp;&nbsp;date )
</h3>
Constructs a datetime with date <em>date</em> and null (but valid) time
(00:00:00.000).

<h3 class=fn><a name="QDateTime-3"></a>QDateTime::QDateTime ( const&nbsp;<a href="qdate.html">QDate</a>&nbsp;&amp;&nbsp;date, const&nbsp;<a href="qtime.html">QTime</a>&nbsp;&amp;&nbsp;time )
</h3>
Constructs a datetime with date <em>date</em> and time <em>time</em>.

<h3 class=fn><a href="qdatetime.html">QDateTime</a> <a name="addDays"></a>QDateTime::addDays ( int&nbsp;ndays ) const
</h3>
Returns a QDateTime object containing a datetime <em>ndays</em> days
later than the datetime of this object (or earlier if <em>ndays</em> is
negative).
<p> <p>See also <a href="#daysTo">daysTo</a>(), <a href="#addMonths">addMonths</a>(), <a href="#addYears">addYears</a>(), and <a href="#addSecs">addSecs</a>().

<h3 class=fn><a href="qdatetime.html">QDateTime</a> <a name="addMonths"></a>QDateTime::addMonths ( int&nbsp;nmonths ) const
</h3>
Returns a QDateTime object containing a datetime <em>nmonths</em> months
later than the datetime of this object (or earlier if <em>nmonths</em>
is negative).
<p> <p>See also <a href="#daysTo">daysTo</a>(), <a href="#addDays">addDays</a>(), <a href="#addYears">addYears</a>(), and <a href="#addSecs">addSecs</a>().

<h3 class=fn><a href="qdatetime.html">QDateTime</a> <a name="addSecs"></a>QDateTime::addSecs ( int&nbsp;nsecs ) const
</h3>
Returns a QDateTime object containing a datetime <em>nsecs</em> seconds
later than the datetime of this object (or earlier if <em>nsecs</em> is
negative).
<p> <p>See also <a href="#secsTo">secsTo</a>(), <a href="#addDays">addDays</a>(), <a href="#addMonths">addMonths</a>(), and <a href="#addYears">addYears</a>().

<p>Example: <a href="listviews-example.html#x136">listviews/listviews.cpp</a>.
<h3 class=fn><a href="qdatetime.html">QDateTime</a> <a name="addYears"></a>QDateTime::addYears ( int&nbsp;nyears ) const
</h3>
Returns a QDateTime object containing a datetime <em>nyears</em> years
later than the datetime of this object (or earlier if <em>nyears</em> is
negative).
<p> <p>See also <a href="#daysTo">daysTo</a>(), <a href="#addDays">addDays</a>(), <a href="#addMonths">addMonths</a>(), and <a href="#addSecs">addSecs</a>().

<h3 class=fn><a href="qdatetime.html">QDateTime</a> <a name="currentDateTime"></a>QDateTime::currentDateTime ( <a href="qt.html#TimeSpec-enum">Qt::TimeSpec</a>&nbsp;ts )<tt> [static]</tt>
</h3>
Returns the current datetime, as reported by the system clock, for the
TimeSpec <em>ts</em>. The default TimeSpec is LocalTime.
<p> <p>See also <a href="qdate.html#currentDate">QDate::currentDate</a>(), <a href="qtime.html#currentTime">QTime::currentTime</a>(), and <a href="qt.html#TimeSpec-enum">Qt::TimeSpec</a>.

<p>Example: <a href="listviews-example.html#x137">listviews/listviews.cpp</a>.
<h3 class=fn><a href="qdatetime.html">QDateTime</a> <a name="currentDateTime-2"></a>QDateTime::currentDateTime ()<tt> [static]</tt>
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns the current datetime, as reported by the system clock.
<p> <p>See also <a href="qdate.html#currentDate">QDate::currentDate</a>() and <a href="qtime.html#currentTime">QTime::currentTime</a>().

<h3 class=fn><a href="qdate.html">QDate</a> <a name="date"></a>QDateTime::date () const
</h3>

<p> Returns the date part of the datetime.
<p> <p>See also <a href="#setDate">setDate</a>() and <a href="#time">time</a>().

<h3 class=fn>int <a name="daysTo"></a>QDateTime::daysTo ( const&nbsp;<a href="qdatetime.html">QDateTime</a>&nbsp;&amp;&nbsp;dt ) const
</h3>
Returns the number of days from this datetime to <em>dt</em> (which is
negative if <em>dt</em> is earlier than this datetime).
<p> <p>See also <a href="#addDays">addDays</a>() and <a href="#secsTo">secsTo</a>().

<h3 class=fn><a href="qdatetime.html">QDateTime</a> <a name="fromString"></a>QDateTime::fromString ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;s, <a href="qt.html#DateFormat-enum">Qt::DateFormat</a>&nbsp;f = Qt::TextDate )<tt> [static]</tt>
</h3>
Returns the QDateTime represented by the string <em>s</em>, using the
format <em>f</em>, or an invalid datetime if this is not possible.
<p> Note for <a href="qt.html#DateFormat-enum">Qt::TextDate</a>: It is recommended that you use the
English short month names (e.g. "Jan"). Although localized month
names can also be used, they depend on the user's locale settings.
<p> <b>Warning:</b> Note that <a href="qt.html#DateFormat-enum">Qt::LocalDate</a> cannot be used here.

<h3 class=fn>bool <a name="isNull"></a>QDateTime::isNull () const
</h3>

<p> Returns TRUE if both the date and the time are null; otherwise
returns FALSE. A null datetime is invalid.
<p> <p>See also <a href="qdate.html#isNull">QDate::isNull</a>() and <a href="qtime.html#isNull">QTime::isNull</a>().

<h3 class=fn>bool <a name="isValid"></a>QDateTime::isValid () const
</h3>

<p> Returns TRUE if both the date and the time are valid; otherwise
returns FALSE.
<p> <p>See also <a href="qdate.html#isValid">QDate::isValid</a>() and <a href="qtime.html#isValid">QTime::isValid</a>().

<h3 class=fn>bool <a name="operator!-eq"></a>QDateTime::operator!= ( const&nbsp;<a href="qdatetime.html">QDateTime</a>&nbsp;&amp;&nbsp;dt ) const
</h3>
Returns TRUE if this datetime is different from <em>dt</em>; otherwise
returns FALSE.
<p> <p>See also <a href="#operator-eq-eq">operator==</a>().

<h3 class=fn>bool <a name="operator-lt"></a>QDateTime::operator&lt; ( const&nbsp;<a href="qdatetime.html">QDateTime</a>&nbsp;&amp;&nbsp;dt ) const
</h3>
Returns TRUE if this datetime is earlier than <em>dt</em>; otherwise
returns FALSE.

<h3 class=fn>bool <a name="operator-lt-eq"></a>QDateTime::operator&lt;= ( const&nbsp;<a href="qdatetime.html">QDateTime</a>&nbsp;&amp;&nbsp;dt ) const
</h3>
Returns TRUE if this datetime is earlier than or equal to <em>dt</em>;
otherwise returns FALSE.

<h3 class=fn>bool <a name="operator-eq-eq"></a>QDateTime::operator== ( const&nbsp;<a href="qdatetime.html">QDateTime</a>&nbsp;&amp;&nbsp;dt ) const
</h3>
Returns TRUE if this datetime is equal to <em>dt</em>; otherwise returns FALSE.
<p> <p>See also <a href="#operator!-eq">operator!=</a>().

<h3 class=fn>bool <a name="operator-gt"></a>QDateTime::operator&gt; ( const&nbsp;<a href="qdatetime.html">QDateTime</a>&nbsp;&amp;&nbsp;dt ) const
</h3>
Returns TRUE if this datetime is later than <em>dt</em>; otherwise
returns FALSE.

<h3 class=fn>bool <a name="operator-gt-eq"></a>QDateTime::operator&gt;= ( const&nbsp;<a href="qdatetime.html">QDateTime</a>&nbsp;&amp;&nbsp;dt ) const
</h3>
Returns TRUE if this datetime is later than or equal to <em>dt</em>;
otherwise returns FALSE.

<h3 class=fn>int <a name="secsTo"></a>QDateTime::secsTo ( const&nbsp;<a href="qdatetime.html">QDateTime</a>&nbsp;&amp;&nbsp;dt ) const
</h3>
Returns the number of seconds from this datetime to <em>dt</em> (which
is negative if <em>dt</em> is earlier than this datetime).
<p> Example:
<pre>
    QDateTime dt = QDateTime::<a href="#currentDateTime">currentDateTime</a>();
    QDateTime xmas( QDate(dt.<a href="#date">date</a>().year(),12,24), QTime(17,00) );
    <a href="qapplication.html#qDebug">qDebug</a>( "There are %d seconds to Christmas", dt.<a href="#secsTo">secsTo</a>(xmas) );
    </pre>
 
<p> <p>See also <a href="#addSecs">addSecs</a>(), <a href="#daysTo">daysTo</a>(), and <a href="qtime.html#secsTo">QTime::secsTo</a>().

<h3 class=fn>void <a name="setDate"></a>QDateTime::setDate ( const&nbsp;<a href="qdate.html">QDate</a>&nbsp;&amp;&nbsp;date )
</h3>

<p> Sets the date part of this datetime to <em>date</em>.
<p> <p>See also <a href="#date">date</a>() and <a href="#setTime">setTime</a>().

<h3 class=fn>void <a name="setTime"></a>QDateTime::setTime ( const&nbsp;<a href="qtime.html">QTime</a>&nbsp;&amp;&nbsp;time )
</h3>

<p> Sets the time part of this datetime to <em>time</em>.
<p> <p>See also <a href="#time">time</a>() and <a href="#setDate">setDate</a>().

<h3 class=fn>void <a name="setTime_t"></a>QDateTime::setTime_t ( uint&nbsp;secsSince1Jan1970UTC, <a href="qt.html#TimeSpec-enum">Qt::TimeSpec</a>&nbsp;ts )
</h3>
Sets the date and time to <em>ts</em> time (<a href="qt.html#TimeSpec-enum">Qt::LocalTime</a> or <a href="qt.html#TimeSpec-enum">Qt::UTC</a>) given the number of seconds that have passed since
1970-01-01T00:00:00, Coordinated Universal Time (UTC). On systems
that do not support timezones this function will behave as if
local time were UTC.
<p> On Windows, only a subset of <em>secsSince1Jan1970UTC</em> values are
supported, as Windows starts counting from 1980.
<p> <p>See also <a href="#toTime_t">toTime_t</a>().

<h3 class=fn>void <a name="setTime_t-2"></a>QDateTime::setTime_t ( uint&nbsp;secsSince1Jan1970UTC )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Convenience function that sets the date and time to local time
based on the given UTC time.

<h3 class=fn><a href="qtime.html">QTime</a> <a name="time"></a>QDateTime::time () const
</h3>

<p> Returns the time part of the datetime.
<p> <p>See also <a href="#setTime">setTime</a>() and <a href="#date">date</a>().

<h3 class=fn><a href="qstring.html">QString</a> <a name="toString"></a>QDateTime::toString ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;format ) const
</h3>
Returns the datetime as a string. The <em>format</em> parameter
determines the format of the result string.
<p> These expressions may be used for the date:
<p> <center><table cellpadding="4" cellspacing="2" border="0">
<tr bgcolor="#a2c511"> <th valign="top">Expression <th valign="top">Output
<tr bgcolor="#f0f0f0"> <td valign="top">d <td valign="top">the day as number without a leading zero (1-31)
<tr bgcolor="#d0d0d0"> <td valign="top">dd <td valign="top">the day as number with a leading zero (01-31)
<tr bgcolor="#f0f0f0"> <td valign="top">ddd
<td valign="top">the abbreviated localized day name (e.g. 'Mon'..'Sun').
Uses <a href="qdate.html#shortDayName">QDate::shortDayName</a>().
<tr bgcolor="#d0d0d0"> <td valign="top">dddd
<td valign="top">the long localized day name (e.g. 'Monday'..'Sunday').
Uses <a href="qdate.html#longDayName">QDate::longDayName</a>().
<tr bgcolor="#f0f0f0"> <td valign="top">M <td valign="top">the month as number without a leading zero (1-12)
<tr bgcolor="#d0d0d0"> <td valign="top">MM <td valign="top">the month as number with a leading zero (01-12)
<tr bgcolor="#f0f0f0"> <td valign="top">MMM
<td valign="top">the abbreviated localized month name (e.g. 'Jan'..'Dec').
Uses <a href="qdate.html#shortMonthName">QDate::shortMonthName</a>().
<tr bgcolor="#d0d0d0"> <td valign="top">MMMM
<td valign="top">the long localized month name (e.g. 'January'..'December').
Uses <a href="qdate.html#longMonthName">QDate::longMonthName</a>().
<tr bgcolor="#f0f0f0"> <td valign="top">yy <td valign="top">the year as two digit number (00-99)
<tr bgcolor="#d0d0d0"> <td valign="top">yyyy <td valign="top">the year as four digit number (1752-8000)
</table></center>
<p> These expressions may be used for the time:
<p> <center><table cellpadding="4" cellspacing="2" border="0">
<tr bgcolor="#a2c511"> <th valign="top">Expression <th valign="top">Output
<tr bgcolor="#f0f0f0"> <td valign="top">h
<td valign="top">the hour without a leading zero (0..23 or 1..12 if AM/PM display)
<tr bgcolor="#d0d0d0"> <td valign="top">hh
<td valign="top">the hour with a leading zero (00..23 or 01..12 if AM/PM display)
<tr bgcolor="#f0f0f0"> <td valign="top">m <td valign="top">the minute without a leading zero (0..59)
<tr bgcolor="#d0d0d0"> <td valign="top">mm <td valign="top">the minute with a leading zero (00..59)
<tr bgcolor="#f0f0f0"> <td valign="top">s <td valign="top">the second whithout a leading zero (0..59)
<tr bgcolor="#d0d0d0"> <td valign="top">ss <td valign="top">the second whith a leading zero (00..59)
<tr bgcolor="#f0f0f0"> <td valign="top">z <td valign="top">the milliseconds without leading zeroes (0..999)
<tr bgcolor="#d0d0d0"> <td valign="top">zzz <td valign="top">the milliseconds with leading zeroes (000..999)
<tr bgcolor="#f0f0f0"> <td valign="top">AP
<td valign="top">use AM/PM display. <em>AP</em> will be replaced by either "AM" or "PM".
<tr bgcolor="#d0d0d0"> <td valign="top">ap
<td valign="top">use am/pm display. <em>ap</em> will be replaced by either "am" or "pm".
</table></center>
<p> All other input characters will be ignored.
<p> Example format strings (assumed that the QDateTime is
21<small><sup>st</sup></small> May 2001 14:13:09)
<p> <center><table cellpadding="4" cellspacing="2" border="0">
<tr bgcolor="#a2c511"> <th valign="top">Format <th valign="top">Result
<tr bgcolor="#f0f0f0"> <td valign="top">dd.MM.yyyy	    <td valign="top" colspan="1" rowspan="1"> 21.05.2001
<tr bgcolor="#d0d0d0"> <td valign="top">ddd MMMM d yy   <td valign="top" colspan="1" rowspan="1"> Tue May 21 01
<tr bgcolor="#f0f0f0"> <td valign="top">hh:mm:ss.zzz    <td valign="top" colspan="1" rowspan="1"> 14:13:09.042
<tr bgcolor="#d0d0d0"> <td valign="top">h:m:s ap	    <td valign="top" colspan="1" rowspan="1"> 2:13:9 pm
</table></center>
<p> If the datetime is an invalid datetime, then <a href="qstring.html#QString-null">QString::null</a> will be returned.
<p> <p>See also <a href="qdate.html#toString">QDate::toString</a>() and <a href="qtime.html#toString">QTime::toString</a>().

<h3 class=fn><a href="qstring.html">QString</a> <a name="toString-2"></a>QDateTime::toString ( <a href="qt.html#DateFormat-enum">Qt::DateFormat</a>&nbsp;f = Qt::TextDate ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns the datetime as a string. The <em>f</em> parameter determines
the format of the string.
<p> If <em>f</em> is <a href="qt.html#DateFormat-enum">Qt::TextDate</a>, the string format is "Wed May 20
03:40:13 1998" (using <a href="qdate.html#shortDayName">QDate::shortDayName</a>(), <a href="qdate.html#shortMonthName">QDate::shortMonthName</a>(),
and <a href="qtime.html#toString">QTime::toString</a>() to generate the string, so the day and month
names will have localized names).
<p> If <em>f</em> is <a href="qt.html#DateFormat-enum">Qt::ISODate</a>, the string format corresponds to the
ISO 8601 extended specification for representations of dates and
times, which is YYYY-MM-DDTHH:MM:SS.
<p> If <em>f</em> is <a href="qt.html#DateFormat-enum">Qt::LocalDate</a>, the string format depends on the
locale settings of the system.
<p> If the format <em>f</em> is invalid or the datetime is invalid, <a href="#toString">toString</a>()
returns a null string.
<p> <p>See also <a href="qdate.html#toString">QDate::toString</a>() and <a href="qtime.html#toString">QTime::toString</a>().

<h3 class=fn>uint <a name="toTime_t"></a>QDateTime::toTime_t () const
</h3>
Returns the datetime as the number of seconds that have passed
since 1970-01-01T00:00:00, Coordinated Universal Time (UTC).
<p> On systems that do not support timezones, this function will
behave as if local time were UTC.
<p> <p>See also <a href="#setTime_t">setTime_t</a>().

<hr><h2>Related Functions</h2>
<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt"></a>operator&lt;&lt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, const&nbsp;<a href="qdatetime.html">QDateTime</a>&nbsp;&amp;&nbsp;dt )
</h3>

<p> Writes the datetime <em>dt</em> to the stream <em>s</em>.
<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.

<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt"></a>operator&gt;&gt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, <a href="qdatetime.html">QDateTime</a>&nbsp;&amp;&nbsp;dt )
</h3>

<p> Reads a datetime from the stream <em>s</em> into <em>dt</em>.
<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>