Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QDateTime Class Reference

List of all members.


Detailed Description

The QDateTime class provides date and time functions.

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() that 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 that takes a POSIX-standard "number of seconds since 00:00:00 on January 1, 1970" value. The fromString() function returns a QDateTime, given a string and a date format 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 secsTo() returns the number of seconds between two datetimes.

QDateTime can store datetimes as {Qt::LocalTime}{local time} or as {Qt::UTC}{UTC}. QDateTime::currentDateTime() returns a QDateTime expressed as local time; use toUTC() to convert it to UTC. You can also use timeSpec() to find out if a QDateTime object stores a UTC time or a local time. Operations such as addSecs() and secsTo() are aware of daylight saving time (DST).

See also:
QDate QTime QDateTimeEdit

Definition at line 177 of file qdatetime.h.


Public Member Functions

QDateTime addDays (int days) const
QDateTime addMonths (int months) const
QDateTime addMSecs (qint64 msecs) const
QDateTime addSecs (int secs) const
QDateTime addYears (int years) const
QDate date () const
int daysTo (const QDateTime &) const
bool isNull () const
bool isValid () const
bool operator!= (const QDateTime &other) const
bool operator< (const QDateTime &other) const
bool operator<= (const QDateTime &other) const
QDateTimeoperator= (const QDateTime &other)
bool operator== (const QDateTime &other) const
bool operator> (const QDateTime &other) const
bool operator>= (const QDateTime &other) const
 QDateTime (const QDateTime &other)
 QDateTime (const QDate &, const QTime &, Qt::TimeSpec spec=Qt::LocalTime)
 QDateTime (const QDate &)
 QDateTime ()
int secsTo (const QDateTime &) const
void setDate (const QDate &date)
void setTime (const QTime &time)
void setTime_t (uint secsSince1Jan1970UTC)
void setTimeSpec (Qt::TimeSpec spec)
QTime time () const
Qt::TimeSpec timeSpec () const
QDateTime toLocalTime () const
QString toString (const QString &format) const
QString toString (Qt::DateFormat f=Qt::TextDate) const
uint toTime_t () const
QDateTime toTimeSpec (Qt::TimeSpec spec) const
QDateTime toUTC () const
 ~QDateTime ()

Static Public Member Functions

static QDateTime currentDateTime ()
static QDateTime fromString (const QString &s, const QString &format)
static QDateTime fromString (const QString &s, Qt::DateFormat f=Qt::TextDate)
static QDateTime fromTime_t (uint secsSince1Jan1970UTC)

Private Member Functions

void detach ()

Private Attributes

QDateTimePrivate * d

Friends

Q_CORE_EXPORT QDataStreamoperator<< (QDataStream &, const QDateTime &)
Q_CORE_EXPORT QDataStreamoperator>> (QDataStream &, QDateTime &)
class QDateTimePrivate

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index