1QDateTime(3qt)                                                  QDateTime(3qt)
2
3
4

NAME

6       QDateTime - Date and time functions
7

SYNOPSIS

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       QDateTime ()
16       QDateTime ( const QDate & date )
17       QDateTime ( const QDate & date, const QTime & time )
18       bool isNull () const
19       bool isValid () const
20       QDate date () const
21       QTime time () const
22       uint toTime_t () const
23       void setDate ( const QDate & date )
24       void setTime ( const QTime & time )
25       void setTime_t ( uint secsSince1Jan1970UTC )
26       void setTime_t ( uint secsSince1Jan1970UTC, Qt::TimeSpec ts )
27       QString toString ( Qt::DateFormat f = Qt::TextDate ) const
28       QString toString ( const QString & format ) const
29       QDateTime addDays ( int ndays ) const
30       QDateTime addMonths ( int nmonths ) const
31       QDateTime addYears ( int nyears ) const
32       QDateTime addSecs ( int nsecs ) const
33       int daysTo ( const QDateTime & dt ) const
34       int secsTo ( const QDateTime & dt ) const
35       bool operator== ( const QDateTime & dt ) const
36       bool operator!= ( const QDateTime & dt ) const
37       bool operator< ( const QDateTime & dt ) const
38       bool operator<= ( const QDateTime & dt ) const
39       bool operator> ( const QDateTime & dt ) const
40       bool operator>= ( const QDateTime & dt ) const
41
42   Static Public Members
43       QDateTime currentDateTime ()
44       QDateTime currentDateTime ( Qt::TimeSpec ts )
45       QDateTime fromString ( const QString & s, Qt::DateFormat f =
46           Qt::TextDate )
47
49       QDataStream & operator<< ( QDataStream & s, const QDateTime & dt )
50       QDataStream & operator>> ( QDataStream & s, QDateTime & dt )
51

DESCRIPTION

53       The QDateTime class provides date and time functions.
54
55       A QDateTime object contains a calendar date and a clock time (a"
56       datetime"). It is a combination of the QDate and QTime classes. It can
57       read the current datetime from the system clock. It provides functions
58       for comparing datetimes and for manipulating a datetime by adding a
59       number of seconds, days, months or years.
60
61       A QDateTime object is typically created either by giving a date and
62       time explicitly in the constructor, or by using the static function
63       currentDateTime(), which returns a QDateTime object set to the system
64       clock's time. The date and time can be changed with setDate() and
65       setTime(). A datetime can also be set using the setTime_t() function,
66       which takes a POSIX-standard "number of seconds since 00:00:00 on
67       January 1, 1970" value. The fromString() function returns a QDateTime
68       given a string and a date format which is used to interpret the date
69       within the string.
70
71       The date() and time() functions provide access to the date and time
72       parts of the datetime. The same information is provided in textual
73       format by the toString() function.
74
75       QDateTime provides a full set of operators to compare two QDateTime
76       objects where smaller means earlier and larger means later.
77
78       You can increment (or decrement) a datetime by a given number of
79       seconds using addSecs() or days using addDays(). Similarly you can use
80       addMonths() and addYears(). The daysTo() function returns the number of
81       days between two datetimes, and secsTo() returns the number of seconds
82       between two datetimes.
83
84       The range of a datetime object is constrained to the ranges of the
85       QDate and QTime objects which it embodies.
86
87       See also QDate, QTime, QDateTimeEdit, and Time and Date.
88

MEMBER FUNCTION DOCUMENTATION

QDateTime::QDateTime ()

91       Constructs a null datetime (i.e. null date and null time). A null
92       datetime is invalid, since the date is invalid.
93
94       See also isValid().
95

QDateTime::QDateTime ( const QDate & date )

97       Constructs a datetime with date date and null (but valid) time
98       (00:00:00.000).
99

QDateTime::QDateTime ( const QDate & date, const QTime & time )

101       Constructs a datetime with date date and time time.
102

QDateTime QDateTime::addDays ( int ndays ) const

104       Returns a QDateTime object containing a datetime ndays days later than
105       the datetime of this object (or earlier if ndays is negative).
106
107       See also daysTo(), addMonths(), addYears(), and addSecs().
108

QDateTime QDateTime::addMonths ( int nmonths ) const

110       Returns a QDateTime object containing a datetime nmonths months later
111       than the datetime of this object (or earlier if nmonths is negative).
112
113       See also daysTo(), addDays(), addYears(), and addSecs().
114

QDateTime QDateTime::addSecs ( int nsecs ) const

116       Returns a QDateTime object containing a datetime nsecs seconds later
117       than the datetime of this object (or earlier if nsecs is negative).
118
119       See also secsTo(), addDays(), addMonths(), and addYears().
120
121       Example: listviews/listviews.cpp.
122

QDateTime QDateTime::addYears ( int nyears ) const

124       Returns a QDateTime object containing a datetime nyears years later
125       than the datetime of this object (or earlier if nyears is negative).
126
127       See also daysTo(), addDays(), addMonths(), and addSecs().
128

QDateTime QDateTime::currentDateTime ( Qt::TimeSpec ts ) [static]

130       Returns the current datetime, as reported by the system clock, for the
131       TimeSpec ts. The default TimeSpec is LocalTime.
132
133       See also QDate::currentDate(), QTime::currentTime(), and Qt::TimeSpec.
134
135       Example: listviews/listviews.cpp.
136

QDateTime QDateTime::currentDateTime () [static]

138       This is an overloaded member function, provided for convenience. It
139       behaves essentially like the above function.
140
141       Returns the current datetime, as reported by the system clock.
142
143       See also QDate::currentDate() and QTime::currentTime().
144

QDate QDateTime::date () const

146       Returns the date part of the datetime.
147
148       See also setDate() and time().
149

int QDateTime::daysTo ( const QDateTime & dt ) const

151       Returns the number of days from this datetime to dt (which is negative
152       if dt is earlier than this datetime).
153
154       See also addDays() and secsTo().
155

QDateTime QDateTime::fromString ( const QString & s, Qt::DateFormat f =

157       Qt::TextDate ) [static]
158       Returns the QDateTime represented by the string s, using the format f,
159       or an invalid datetime if this is not possible.
160
161       Note for Qt::TextDate: It is recommended that you use the English short
162       month names (e.g. "Jan"). Although localized month names can also be
163       used, they depend on the user's locale settings.
164
165       Warning: Note that Qt::LocalDate cannot be used here.
166

bool QDateTime::isNull () const

168       Returns TRUE if both the date and the time are null; otherwise returns
169       FALSE. A null datetime is invalid.
170
171       See also QDate::isNull() and QTime::isNull().
172

bool QDateTime::isValid () const

174       Returns TRUE if both the date and the time are valid; otherwise returns
175       FALSE.
176
177       See also QDate::isValid() and QTime::isValid().
178

bool QDateTime::operator!= ( const QDateTime & dt ) const

180       Returns TRUE if this datetime is different from dt; otherwise returns
181       FALSE.
182
183       See also operator==().
184

bool QDateTime::operator< ( const QDateTime & dt ) const

186       Returns TRUE if this datetime is earlier than dt; otherwise returns
187       FALSE.
188

bool QDateTime::operator<= ( const QDateTime & dt ) const

190       Returns TRUE if this datetime is earlier than or equal to dt; otherwise
191       returns FALSE.
192

bool QDateTime::operator== ( const QDateTime & dt ) const

194       Returns TRUE if this datetime is equal to dt; otherwise returns FALSE.
195
196       See also operator!=().
197

bool QDateTime::operator> ( const QDateTime & dt ) const

199       Returns TRUE if this datetime is later than dt; otherwise returns
200       FALSE.
201

bool QDateTime::operator>= ( const QDateTime & dt ) const

203       Returns TRUE if this datetime is later than or equal to dt; otherwise
204       returns FALSE.
205

int QDateTime::secsTo ( const QDateTime & dt ) const

207       Returns the number of seconds from this datetime to dt (which is
208       negative if dt is earlier than this datetime).
209
210       Example:
211
212           QDateTime dt = QDateTime::currentDateTime();
213           QDateTime xmas( QDate(dt.date().year(),12,24), QTime(17,00) );
214           qDebug( "There are %d seconds to Christmas", dt.secsTo(xmas) );
215
216       See also addSecs(), daysTo(), and QTime::secsTo().
217

void QDateTime::setDate ( const QDate & date )

219       Sets the date part of this datetime to date.
220
221       See also date() and setTime().
222

void QDateTime::setTime ( const QTime & time )

224       Sets the time part of this datetime to time.
225
226       See also time() and setDate().
227

void QDateTime::setTime_t ( uint secsSince1Jan1970UTC, Qt::TimeSpec ts )

229       Sets the date and time to ts time (Qt::LocalTime or Qt::UTC) given the
230       number of seconds that have passed since 1970-01-01T00:00:00,
231       Coordinated Universal Time (UTC). On systems that do not support
232       timezones this function will behave as if local time were UTC.
233
234       On Windows, only a subset of secsSince1Jan1970UTC values are supported,
235       as Windows starts counting from 1980.
236
237       See also toTime_t().
238

void QDateTime::setTime_t ( uint secsSince1Jan1970UTC )

240       This is an overloaded member function, provided for convenience. It
241       behaves essentially like the above function.
242
243       Convenience function that sets the date and time to local time based on
244       the given UTC time.
245

QTime QDateTime::time () const

247       Returns the time part of the datetime.
248
249       See also setTime() and date().
250

QString QDateTime::toString ( const QString & format ) const

252       Returns the datetime as a string. The format parameter determines the
253       format of the result string.
254
255       These expressions may be used for the date:
256
257       <center>.nf
258
259       </center>
260
261       These expressions may be used for the time:
262
263       <center>.nf
264
265       </center>
266
267       All other input characters will be ignored.
268
269       Example format strings (assumed that the QDateTime is
270       21<small><sup>st</sup></small> May 2001 14:13:09)
271
272       <center>.nf
273
274       </center>
275
276       If the datetime is an invalid datetime, then QString::null will be
277       returned.
278
279       See also QDate::toString() and QTime::toString().
280

QString QDateTime::toString ( Qt::DateFormat f = Qt::TextDate ) const

282       This is an overloaded member function, provided for convenience. It
283       behaves essentially like the above function.
284
285       Returns the datetime as a string. The f parameter determines the format
286       of the string.
287
288       If f is Qt::TextDate, the string format is "Wed May 20 03:40:13 1998"
289       (using QDate::shortDayName(), QDate::shortMonthName(), and
290       QTime::toString() to generate the string, so the day and month names
291       will have localized names).
292
293       If f is Qt::ISODate, the string format corresponds to the ISO 8601
294       extended specification for representations of dates and times, which is
295       YYYY-MM-DDTHH:MM:SS.
296
297       If f is Qt::LocalDate, the string format depends on the locale settings
298       of the system.
299
300       If the format f is invalid or the datetime is invalid, toString()
301       returns a null string.
302
303       See also QDate::toString() and QTime::toString().
304

uint QDateTime::toTime_t () const

306       Returns the datetime as the number of seconds that have passed since
307       1970-01-01T00:00:00, Coordinated Universal Time (UTC).
308
309       On systems that do not support timezones, this function will behave as
310       if local time were UTC.
311
312       See also setTime_t().
313

QDataStream & operator<< ( QDataStream & s, const QDateTime & dt )

316       Writes the datetime dt to the stream s.
317
318       See also Format of the QDataStream operators.
319

QDataStream & operator>> ( QDataStream & s, QDateTime & dt )

321       Reads a datetime from the stream s into dt.
322
323       See also Format of the QDataStream operators.
324
325

SEE ALSO

327       http://doc.trolltech.com/qdatetime.html
328       http://www.trolltech.com/faq/tech.html
329
331       Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
332       license file included in the distribution for a complete license
333       statement.
334

AUTHOR

336       Generated automatically from the source code.
337

BUGS

339       If you find a bug in Qt, please report it as described in
340       http://doc.trolltech.com/bughowto.html.  Good bug reports help us to
341       help you. Thank you.
342
343       The definitive Qt documentation is provided in HTML format; it is
344       located at $QTDIR/doc/html and can be read using Qt Assistant or with a
345       web browser. This man page is provided as a convenience for those users
346       who prefer man pages, although this format is not officially supported
347       by Trolltech.
348
349       If you find errors in this manual page, please report them to qt-
350       bugs@trolltech.com.  Please include the name of the manual page
351       (qdatetime.3qt) and the Qt version (3.3.8).
352
353
354
355Trolltech AS                    2 February 2007                 QDateTime(3qt)
Impressum