![]() |
| ||
Classes - Annotated - Tree - Functions - Home - Structure |
The QDateTime class provides date and time functions. More...
#include <qdatetime.h>
A QDateTime object contains a calendar date and a clock time (a "datetime"). It is a combination of the QDate and QTime 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.
A QDateTime object is typically created either by giving a date and time explicitly in the constructor, or by using the static function currentDateTime(), which returns a QDateTime object set to the system clock's time. The date and time can be changed with setDate() and setTime(). A datetime can also be set using the setTime_t() function, which takes a POSIX-standard "number of seconds since 00:00:00 on January 1, 1970" value. The fromString() function returns a QDate given a string and a date format which is used to interpret the date within the string.
The date() and time() functions provide access to the date and time parts of the datetime. The same information is provided in textual format by the toString() function.
QDateTime provides a full set of operators to compare two QDateTime objects where smaller means earlier and larger means later.
You can increment (or decrement) a datetime by a given number of seconds using addSecs() or days using addDays(). Similarly you can use addMonths() and addYears(). The daysTo() function returns the number of days between two datetimes, and sectTo() returns the number of seconds between two datetimes.
The range of a datetime object is constrained to the ranges of the QDate and QTime objects which it embodies.
See also QDate, QTime and QDateTimeEdit.
Constructs a null datetime (i.e. null date and null time). A null datetime is invalid, since the date is invalid.
See also isValid().
See also daysTo(), addMonths(), addYears() and addSecs().
See also daysTo(), addDays(), addYears() and addSecs().
See also secsTo(), addDays(), addMonths() and addYears().
Example: listviews/listviews.cpp.
See also daysTo(), addDays(), addMonths() and addSecs().
See also QDate::currentDate() and QTime::currentTime().
Example: listviews/listviews.cpp.
Returns the date part of the datetime.
See also setDate() and time().
See also addDays() and secsTo().
Returns TRUE if both the date and the time are null; otherwise returns FALSE. A null datetime is invalid.
See also QDate::isNull() and QTime::isNull().
Returns TRUE if both the date and the time are valid; otherwise returns FALSE.
See also QDate::isValid() and QTime::isValid().
See also operator==().
See also operator!=().
Example:
QDateTime dt = QDateTime::currentDateTime(); QDateTime xmas( QDate(dt.year(),12,24), QTime(17,00) ); qDebug( "There are %d seconds to Christmas", dt.secsTo(xmas) );
See also addSecs(), daysTo() and QTime::secsTo().
Example: network/ftpclient/ftpview.cpp.
Sets the date part of this datetime to date.
See also date() and setTime().
Sets the time part of this datetime to time.
See also time() and setDate().
Note that Microsoft Windows supports only a limited range of values for secsSince1Jan1970UTC.
Returns the time part of the datetime.
See also setTime() and date().
If f is Qt::TextDate, the string format is "Sat May 20 03:40:13 1998" (using QDate::shortDayName(), QDate::shortMonthName(), and QTime::toString() to generate the string).
If f is Qt::ISODate, the string format corresponds to the ISO 8601 specification for representations of dates and times, which is YYYY-MM-DDTHH:MM:SS.
If the format f is invalid, toString() returns a null string.
See also QDate::toString() and QTime::toString.
See also Format of the QDataStream operators.
See also Format of the QDataStream operators.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.
Copyright © 2001 Trolltech | Trademarks | Qt version 3.0.0-beta1-beta1
|