1QDate(3qt) QDate(3qt)
2
3
4
6 QDate - Date 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 QDate ()
16 QDate ( int y, int m, int d )
17 bool isNull () const
18 bool isValid () const
19 int year () const
20 int month () const
21 int day () const
22 int dayOfWeek () const
23 int dayOfYear () const
24 int daysInMonth () const
25 int daysInYear () const
26 int weekNumber ( int * yearNumber = 0 ) const
27 QString toString ( Qt::DateFormat f = Qt::TextDate ) const
28 QString toString ( const QString & format ) const
29 bool setYMD ( int y, int m, int d )
30 QDate addDays ( int ndays ) const
31 QDate addMonths ( int nmonths ) const
32 QDate addYears ( int nyears ) const
33 int daysTo ( const QDate & d ) const
34 bool operator== ( const QDate & d ) const
35 bool operator!= ( const QDate & d ) const
36 bool operator< ( const QDate & d ) const
37 bool operator<= ( const QDate & d ) const
38 bool operator> ( const QDate & d ) const
39 bool operator>= ( const QDate & d ) const
40
41 Static Public Members
42 QString monthName ( int month ) (obsolete)
43 QString dayName ( int weekday ) (obsolete)
44 QString shortMonthName ( int month )
45 QString shortDayName ( int weekday )
46 QString longMonthName ( int month )
47 QString longDayName ( int weekday )
48 QDate currentDate ()
49 QDate currentDate ( Qt::TimeSpec ts )
50 QDate fromString ( const QString & s, Qt::DateFormat f = Qt::TextDate )
51 bool isValid ( int y, int m, int d )
52 bool leapYear ( int y )
53
55 QDataStream & operator<< ( QDataStream & s, const QDate & d )
56 QDataStream & operator>> ( QDataStream & s, QDate & d )
57
59 The QDate class provides date functions.
60
61 A QDate object contains a calendar date, i.e. year, month, and day
62 numbers, in the modern Western (Gregorian) calendar. It can read the
63 current date from the system clock. It provides functions for comparing
64 dates and for manipulating dates, e.g. by adding a number of days or
65 months or years.
66
67 A QDate object is typically created either by giving the year, month
68 and day numbers explicitly, or by using the static function
69 currentDate(), which creates a QDate object containing the system
70 clock's date. An explicit date can also be set using setYMD(). The
71 fromString() function returns a QDate given a string and a date format
72 which is used to interpret the date within the string.
73
74 The year(), month(), and day() functions provide access to the year,
75 month, and day numbers. Also, dayOfWeek() and dayOfYear() functions are
76 provided. The same information is provided in textual format by the
77 toString(), shortDayName(), longDayName(), shortMonthName() and
78 longMonthName() functions.
79
80 QDate provides a full set of operators to compare two QDate objects
81 where smaller means earlier and larger means later.
82
83 You can increment (or decrement) a date by a given number of days using
84 addDays(). Similarly you can use addMonths() and addYears(). The
85 daysTo() function returns the number of days between two dates.
86
87 The daysInMonth() and daysInYear() functions return how many days there
88 are in this date's month and year, respectively. The leapYear()
89 function indicates whether this date is in a leap year.
90
91 Note that QDate should not be used for date calculations for dates
92 prior to the introduction of the Gregorian calendar. This calendar was
93 adopted by England from the 14<sup><small>th</small></sup> September
94 1752 (hence this is the earliest valid QDate), and subsequently by most
95 other Western countries, until 1923.
96
97 The end of time is reached around the year 8000, by which time we
98 expect Qt to be obsolete.
99
100 See also QTime, QDateTime, QDateEdit, QDateTimeEdit, and Time and Date.
101
104 Constructs a null date. Null dates are invalid.
105
106 See also isNull() and isValid().
107
109 Constructs a date with year y, month m and day d.
110
111 y must be in the range 1752..8000, m must be in the range 1..12, and d
112 must be in the range 1..31.
113
114 Warning: If y is in the range 0..99, it is interpreted as 1900..1999.
115
116 See also isValid().
117
119 Returns a QDate object containing a date ndays later than the date of
120 this object (or earlier if ndays is negative).
121
122 See also addMonths(), addYears(), and daysTo().
123
125 Returns a QDate object containing a date nmonths later than the date of
126 this object (or earlier if nmonths is negative).
127
128 See also addDays() and addYears().
129
131 Returns a QDate object containing a date nyears later than the date of
132 this object (or earlier if nyears is negative).
133
134 See also addDays() and addMonths().
135
137 Returns the current date, as reported by the system clock, for the
138 TimeSpec ts. The default TimeSpec is LocalTime.
139
140 See also QTime::currentTime(), QDateTime::currentDateTime(), and
141 Qt::TimeSpec.
142
143 Example: dclock/dclock.cpp.
144
146 This is an overloaded member function, provided for convenience. It
147 behaves essentially like the above function.
148
149 Returns the current date, as reported by the system clock.
150
151 See also QTime::currentTime() and QDateTime::currentDateTime().
152
154 Returns the day of the month (1..31) of this date.
155
156 See also year(), month(), and dayOfWeek().
157
158 Example: dclock/dclock.cpp.
159
161 This function is obsolete. It is provided to keep old source working.
162 We strongly advise against using it in new code.
163
164 Use shortDayName() instead.
165
167 Returns the weekday (Monday=1..Sunday=7) for this date.
168
169 See also day() and dayOfYear().
170
172 Returns the day of the year (1..365) for this date.
173
174 See also day() and dayOfWeek().
175
177 Returns the number of days in the month (28..31) for this date.
178
179 See also day() and daysInYear().
180
182 Returns the number of days in the year (365 or 366) for this date.
183
184 See also day() and daysInMonth().
185
187 Returns the number of days from this date to d (which is negative if d
188 is earlier than this date).
189
190 Example:
191
192 QDate d1( 1995, 5, 17 ); // May 17th 1995
193 QDate d2( 1995, 5, 20 ); // May 20th 1995
194 d1.daysTo( d2 ); // returns 3
195 d2.daysTo( d1 ); // returns -3
196
197 See also addDays().
198
200 [static]
201 Returns the QDate represented by the string s, using the format f, or
202 an invalid date if the string cannot be parsed.
203
204 Note for Qt::TextDate: It is recommended that you use the English short
205 month names (e.g. "Jan"). Although localized month names can also be
206 used, they depend on the user's locale settings.
207
208 Warning: Qt::LocalDate cannot be used here.
209
211 Returns TRUE if the date is null; otherwise returns FALSE. A null date
212 is invalid.
213
214 See also isValid().
215
217 Returns TRUE if this date is valid; otherwise returns FALSE.
218
219 See also isNull().
220
222 This is an overloaded member function, provided for convenience. It
223 behaves essentially like the above function.
224
225 Returns TRUE if the specified date (year y, month m and day d) is
226 valid; otherwise returns FALSE.
227
228 Example:
229
230 QDate::isValid( 2002, 5, 17 ); // TRUE May 17th 2002 is valid
231 QDate::isValid( 2002, 2, 30 ); // FALSE Feb 30th does not exist
232 QDate::isValid( 2004, 2, 29 ); // TRUE 2004 is a leap year
233 QDate::isValid( 1202, 6, 6 ); // FALSE 1202 is pre-Gregorian
234
235 Warning: A y value in the range 00..99 is interpreted as 1900..1999.
236
237 See also isNull() and setYMD().
238
240 Returns TRUE if the specified year y is a leap year; otherwise returns
241 FALSE.
242
244 Returns the long name of the weekday.
245
246 1 = "Monday", 2 = "Tuesday", ... 7 = "Sunday"
247
248 The day names will be localized according to the system's locale
249 settings.
250
251 See also toString(), shortDayName(), shortMonthName(), and
252 longMonthName().
253
255 Returns the long name of the month.
256
257 1 = "January", 2 = "February", ... 12 = "December"
258
259 The month names will be localized according to the system's locale
260 settings.
261
262 See also toString(), shortMonthName(), shortDayName(), and
263 longDayName().
264
266 Returns the month (January=1..December=12) of this date.
267
268 See also year() and day().
269
270 Example: dclock/dclock.cpp.
271
273 This function is obsolete. It is provided to keep old source working.
274 We strongly advise against using it in new code.
275
276 Use shortMonthName() instead.
277
279 Returns TRUE if this date is different from d; otherwise returns FALSE.
280
282 Returns TRUE if this date is earlier than d, otherwise returns FALSE.
283
285 Returns TRUE if this date is earlier than or equal to d, otherwise
286 returns FALSE.
287
289 Returns TRUE if this date is equal to d; otherwise returns FALSE.
290
292 Returns TRUE if this date is later than d, otherwise returns FALSE.
293
295 Returns TRUE if this date is later than or equal to d, otherwise
296 returns FALSE.
297
299 Sets the date's year y, month m and day d.
300
301 y must be in the range 1752..8000, m must be in the range 1..12, and d
302 must be in the range 1..31.
303
304 Warning: If y is in the range 0..99, it is interpreted as 1900..1999.
305
306 Returns TRUE if the date is valid; otherwise returns FALSE.
307
309 Returns the name of the weekday.
310
311 1 = "Mon", 2 = "Tue", ... 7 = "Sun"
312
313 The day names will be localized according to the system's locale
314 settings.
315
316 See also toString(), shortMonthName(), longMonthName(), and
317 longDayName().
318
320 Returns the name of the month.
321
322 1 = "Jan", 2 = "Feb", ... 12 = "Dec"
323
324 The month names will be localized according to the system's locale
325 settings.
326
327 See also toString(), longMonthName(), shortDayName(), and
328 longDayName().
329
331 Returns the date as a string. The format parameter determines the
332 format of the result string.
333
334 These expressions may be used:
335
336 <center>.nf
337
338 </center>
339
340 All other input characters will be ignored.
341
342 Example format strings (assuming that the QDate is the
343 20<sup><small>th</small></sup> July 1969): <center>.nf
344
345 </center>
346
347 If the date is an invalid date, then QString::null will be returned.
348
349 See also QDateTime::toString() and QTime::toString().
350
352 This is an overloaded member function, provided for convenience. It
353 behaves essentially like the above function.
354
355 Returns the date as a string. The f parameter determines the format of
356 the string.
357
358 If f is Qt::TextDate, the string format is "Sat May 20 1995" (using the
359 shortDayName() and shortMonthName() functions to generate the string,
360 so the day and month names are locale specific).
361
362 If f is Qt::ISODate, the string format corresponds to the ISO 8601
363 specification for representations of dates, which is YYYY-MM-DD where
364 YYYY is the year, MM is the month of the year (between 01 and 12), and
365 DD is the day of the month between 01 and 31.
366
367 If f is Qt::LocalDate, the string format depends on the locale settings
368 of the system.
369
370 If the date is an invalid date, then QString::null will be returned.
371
372 See also shortDayName() and shortMonthName().
373
375 Returns the week number (1 to 53), and stores the year in *yearNumber
376 unless yearNumber is null (the default).
377
378 Returns 0 if the date is invalid.
379
380 In accordance with ISO 8601, weeks start on Monday and the first
381 Thursday of a year is always in week 1 of that year. Most years have 52
382 weeks, but some have 53.
383
384 *yearNumber is not always the same as year(). For example, 1 January
385 2000 has week number 52 in the year 1999, and 31 December 2002 has week
386 number 1 in the year 2003.
387
388 Copyright (c) 1989 The Regents of the University of California. All
389 rights reserved.
390
391 Redistribution and use in source and binary forms are permitted
392 provided that the above copyright notice and this paragraph are
393 duplicated in all such forms and that any documentation, advertising
394 materials, and other materials related to such distribution and use
395 acknowledge that the software was developed by the University of
396 California, Berkeley. The name of the University may not be used to
397 endorse or promote products derived from this software without specific
398 prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND
399 WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
400 LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
401 PARTICULAR PURPOSE.
402
403 See also isValid().
404
406 Returns the year (1752..8000) of this date.
407
408 See also month() and day().
409
412 Writes the date, d, to the data stream, s.
413
414 See also Format of the QDataStream operators.
415
417 Reads a date from the stream s into d.
418
419 See also Format of the QDataStream operators.
420
421
423 http://doc.trolltech.com/qdate.html
424 http://www.trolltech.com/faq/tech.html
425
427 Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
428 license file included in the distribution for a complete license
429 statement.
430
432 Generated automatically from the source code.
433
435 If you find a bug in Qt, please report it as described in
436 http://doc.trolltech.com/bughowto.html. Good bug reports help us to
437 help you. Thank you.
438
439 The definitive Qt documentation is provided in HTML format; it is
440 located at $QTDIR/doc/html and can be read using Qt Assistant or with a
441 web browser. This man page is provided as a convenience for those users
442 who prefer man pages, although this format is not officially supported
443 by Trolltech.
444
445 If you find errors in this manual page, please report them to qt-
446 bugs@trolltech.com. Please include the name of the manual page
447 (qdate.3qt) and the Qt version (3.3.8).
448
449
450
451Trolltech AS 2 February 2007 QDate(3qt)