You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
394 lines
24 KiB
394 lines
24 KiB
14 years ago
|
<!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 Classes</font></a>
|
||
|
| <a href="mainclasses.html">
|
||
|
<font color="#004faf">Main Classes</font></a>
|
||
|
| <a href="annotated.html">
|
||
|
<font color="#004faf">Annotated</font></a>
|
||
|
| <a href="groups.html">
|
||
|
<font color="#004faf">Grouped 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 <<a href="qdatetime-h.html">qdatetime.h</a>></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 QDate & date )</li>
|
||
|
<li class=fn><a href="#QDateTime-3"><b>QDateTime</b></a> ( const QDate & date, const QTime & 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 QDate & date )</li>
|
||
|
<li class=fn>void <a href="#setTime"><b>setTime</b></a> ( const QTime & time )</li>
|
||
|
<li class=fn>void <a href="#setTime_t-2"><b>setTime_t</b></a> ( uint secsSince1Jan1970UTC )</li>
|
||
|
<li class=fn>void <a href="#setTime_t"><b>setTime_t</b></a> ( uint secsSince1Jan1970UTC, Qt::TimeSpec ts )</li>
|
||
|
<li class=fn>QString <a href="#toString-2"><b>toString</b></a> ( Qt::DateFormat f = Qt::TextDate ) const</li>
|
||
|
<li class=fn>QString <a href="#toString"><b>toString</b></a> ( const QString & format ) const</li>
|
||
|
<li class=fn>QDateTime <a href="#addDays"><b>addDays</b></a> ( int ndays ) const</li>
|
||
|
<li class=fn>QDateTime <a href="#addMonths"><b>addMonths</b></a> ( int nmonths ) const</li>
|
||
|
<li class=fn>QDateTime <a href="#addYears"><b>addYears</b></a> ( int nyears ) const</li>
|
||
|
<li class=fn>QDateTime <a href="#addSecs"><b>addSecs</b></a> ( int nsecs ) const</li>
|
||
|
<li class=fn>int <a href="#daysTo"><b>daysTo</b></a> ( const QDateTime & dt ) const</li>
|
||
|
<li class=fn>int <a href="#secsTo"><b>secsTo</b></a> ( const QDateTime & dt ) const</li>
|
||
|
<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const QDateTime & dt ) const</li>
|
||
|
<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const QDateTime & dt ) const</li>
|
||
|
<li class=fn>bool <a href="#operator-lt"><b>operator<</b></a> ( const QDateTime & dt ) const</li>
|
||
|
<li class=fn>bool <a href="#operator-lt-eq"><b>operator<=</b></a> ( const QDateTime & dt ) const</li>
|
||
|
<li class=fn>bool <a href="#operator-gt"><b>operator></b></a> ( const QDateTime & dt ) const</li>
|
||
|
<li class=fn>bool <a href="#operator-gt-eq"><b>operator>=</b></a> ( const QDateTime & 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 ts )</li>
|
||
|
<li class=fn>QDateTime <a href="#fromString"><b>fromString</b></a> ( const QString & s, Qt::DateFormat f = Qt::TextDate )</li>
|
||
|
</ul>
|
||
|
<h2>Related Functions</h2>
|
||
|
<ul>
|
||
|
<li class=fn>QDataStream & <a href="#operator-lt-lt"><b>operator<<</b></a> ( QDataStream & s, const QDateTime & dt )</li>
|
||
|
<li class=fn>QDataStream & <a href="#operator-gt-gt"><b>operator>></b></a> ( QDataStream & s, QDateTime & 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 <a href="qdate.html">QDate</a> & 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 <a href="qdate.html">QDate</a> & date, const <a href="qtime.html">QTime</a> & 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 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 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 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 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> 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 <a href="qdatetime.html">QDateTime</a> & 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 <a href="qstring.html">QString</a> & s, <a href="qt.html#DateFormat-enum">Qt::DateFormat</a> 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 <a href="qdatetime.html">QDateTime</a> & 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< ( const <a href="qdatetime.html">QDateTime</a> & 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<= ( const <a href="qdatetime.html">QDateTime</a> & 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 <a href="qdatetime.html">QDateTime</a> & 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> ( const <a href="qdatetime.html">QDateTime</a> & 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>= ( const <a href="qdatetime.html">QDateTime</a> & 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 <a href="qdatetime.html">QDateTime</a> & 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 <a href="qdate.html">QDate</a> & 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 <a href="qtime.html">QTime</a> & 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 secsSince1Jan1970UTC, <a href="qt.html#TimeSpec-enum">Qt::TimeSpec</a> 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 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 <a href="qstring.html">QString</a> & 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> 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> & <a name="operator-lt-lt"></a>operator<< ( <a href="qdatastream.html">QDataStream</a> & s, const <a href="qdatetime.html">QDateTime</a> & 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> & <a name="operator-gt-gt"></a>operator>> ( <a href="qdatastream.html">QDataStream</a> & s, <a href="qdatetime.html">QDateTime</a> & 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 © 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 © 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>
|