1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QDateTime Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" 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="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QDateTime Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QDateTime class provides date and time functions. <a href="#details">More...</a></p>
<h3>Methods</h3><ul><li><div class="fn" /><b><a href="qdatetime.html#QDateTime">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qdatetime.html#QDateTime-2">__init__</a></b> (<i>self</i>, QDateTime <i>other</i>)</li><li><div class="fn" /><b><a href="qdatetime.html#QDateTime-3">__init__</a></b> (<i>self</i>, QDate)</li><li><div class="fn" /><b><a href="qdatetime.html#QDateTime-4">__init__</a></b> (<i>self</i>, QDate <i>date</i>, QTime <i>time</i>, Qt.TimeSpec <i>timeSpec</i> = Qt.LocalTime)</li><li><div class="fn" /><b><a href="qdatetime.html#QDateTime-5">__init__</a></b> (<i>self</i>, int <i>y</i>, int <i>m</i>, int <i>d</i>, int <i>h</i>, int <i>m</i>, int <i>s</i> = 0, int <i>msec</i> = 0, int <i>timeSpec</i> = 0)</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#addDays">addDays</a></b> (<i>self</i>, int <i>days</i>)</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#addMonths">addMonths</a></b> (<i>self</i>, int <i>months</i>)</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#addMSecs">addMSecs</a></b> (<i>self</i>, int <i>msecs</i>)</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#addSecs">addSecs</a></b> (<i>self</i>, int <i>secs</i>)</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#addYears">addYears</a></b> (<i>self</i>, int <i>years</i>)</li><li><div class="fn" />QDate <b><a href="qdatetime.html#date">date</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qdatetime.html#daysTo">daysTo</a></b> (<i>self</i>, QDateTime)</li><li><div class="fn" />bool <b><a href="qdatetime.html#isNull">isNull</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qdatetime.html#isValid">isValid</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qdatetime.html#msecsTo">msecsTo</a></b> (<i>self</i>, QDateTime)</li><li><div class="fn" />int <b><a href="qdatetime.html#secsTo">secsTo</a></b> (<i>self</i>, QDateTime)</li><li><div class="fn" /><b><a href="qdatetime.html#setDate">setDate</a></b> (<i>self</i>, QDate <i>date</i>)</li><li><div class="fn" /><b><a href="qdatetime.html#setMSecsSinceEpoch">setMSecsSinceEpoch</a></b> (<i>self</i>, int <i>msecs</i>)</li><li><div class="fn" /><b><a href="qdatetime.html#setTime">setTime</a></b> (<i>self</i>, QTime <i>time</i>)</li><li><div class="fn" /><b><a href="qdatetime.html#setTime_t">setTime_t</a></b> (<i>self</i>, int <i>secsSince1Jan1970UTC</i>)</li><li><div class="fn" /><b><a href="qdatetime.html#setTimeSpec">setTimeSpec</a></b> (<i>self</i>, Qt.TimeSpec <i>spec</i>)</li><li><div class="fn" />QTime <b><a href="qdatetime.html#time">time</a></b> (<i>self</i>)</li><li><div class="fn" />Qt.TimeSpec <b><a href="qdatetime.html#timeSpec">timeSpec</a></b> (<i>self</i>)</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#toLocalTime">toLocalTime</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qdatetime.html#toMSecsSinceEpoch">toMSecsSinceEpoch</a></b> (<i>self</i>)</li><li><div class="fn" />datetime.datetime <b><a href="qdatetime.html#toPyDateTime">toPyDateTime</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qdatetime.html#toString">toString</a></b> (<i>self</i>, Qt.DateFormat <i>format</i> = Qt.TextDate)</li><li><div class="fn" />QString <b><a href="qdatetime.html#toString-2">toString</a></b> (<i>self</i>, QString <i>format</i>)</li><li><div class="fn" />int <b><a href="qdatetime.html#toTime_t">toTime_t</a></b> (<i>self</i>)</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#toTimeSpec">toTimeSpec</a></b> (<i>self</i>, Qt.TimeSpec <i>spec</i>)</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#toUTC">toUTC</a></b> (<i>self</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />QDateTime <b><a href="qdatetime.html#currentDateTime">currentDateTime</a></b> ()</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#currentDateTimeUtc">currentDateTimeUtc</a></b> ()</li><li><div class="fn" />int <b><a href="qdatetime.html#currentMSecsSinceEpoch">currentMSecsSinceEpoch</a></b> ()</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#fromMSecsSinceEpoch">fromMSecsSinceEpoch</a></b> (int <i>msecs</i>)</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#fromString">fromString</a></b> (QString <i>string</i>, Qt.DateFormat <i>format</i> = Qt.TextDate)</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#fromString-2">fromString</a></b> (QString <i>s</i>, QString <i>format</i>)</li><li><div class="fn" />QDateTime <b><a href="qdatetime.html#fromTime_t">fromTime_t</a></b> (int <i>secsSince1Jan1970UTC</i>)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" />int <b><a href="qdatetime.html#__bool__">__bool__</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qdatetime.html#__eq__">__eq__</a></b> (<i>self</i>, QDateTime <i>other</i>)</li><li><div class="fn" />bool <b><a href="qdatetime.html#__ge__">__ge__</a></b> (<i>self</i>, QDateTime <i>other</i>)</li><li><div class="fn" />bool <b><a href="qdatetime.html#__gt__">__gt__</a></b> (<i>self</i>, QDateTime <i>other</i>)</li><li><div class="fn" />int <b><a href="qdatetime.html#__hash__">__hash__</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qdatetime.html#__le__">__le__</a></b> (<i>self</i>, QDateTime <i>other</i>)</li><li><div class="fn" />bool <b><a href="qdatetime.html#__lt__">__lt__</a></b> (<i>self</i>, QDateTime <i>other</i>)</li><li><div class="fn" />bool <b><a href="qdatetime.html#__ne__">__ne__</a></b> (<i>self</i>, QDateTime <i>other</i>)</li><li><div class="fn" />str <b><a href="qdatetime.html#__repr__">__repr__</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>This class can be pickled.</p><p>A Python datetime object
may be used whenever a
<a href="qdatetime.html">QDateTime</a>
is expected.</p>
<p>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>
<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="qdatetime.html#currentDateTime">currentDateTime</a>() that returns
a QDateTime object set to the system clock's time. The date and
time can be changed with <a href="qdatetime.html#setDate">setDate</a>() and <a href="qdatetime.html#setTime">setTime</a>(). A datetime can also be set
using the <a href="qdatetime.html#setTime_t">setTime_t</a>()
function that takes a POSIX-standard "number of seconds since
00:00:00 on January 1, 1970" value. The <a href="qdatetime.html#fromString">fromString</a>() function returns a
QDateTime, given a string and a date format used to interpret the
date within the string.</p>
<p>The <a href="qdatetime.html#date">date</a>() and <a href="qdatetime.html#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="qdatetime.html#toString">toString</a>() function.</p>
<p>QDateTime provides a full set of operators to compare two
QDateTime objects where smaller means earlier and larger means
later.</p>
<p>You can increment (or decrement) a datetime by a given number of
milliseconds using <a href="qdatetime.html#addMSecs">addMSecs</a>(), seconds using <a href="qdatetime.html#addSecs">addSecs</a>(), or days using <a href="qdatetime.html#addDays">addDays</a>(). Similarly you can use
<a href="qdatetime.html#addMonths">addMonths</a>() and <a href="qdatetime.html#addYears">addYears</a>(). The <a href="qdatetime.html#daysTo">daysTo</a>() function returns the number of
days between two datetimes, <a href="qdatetime.html#secsTo">secsTo</a>() returns the number of seconds
between two datetimes, and <a href="qdatetime.html#msecsTo">msecsTo</a>() returns the number of
milliseconds between two datetimes.</p>
<p>QDateTime can store datetimes as <a href="qt.html#TimeSpec-enum">local time</a> or as <a href="qt.html#TimeSpec-enum">UTC</a>. <a href="qdatetime.html#currentDateTime">QDateTime.currentDateTime</a>()
returns a QDateTime expressed as local time; use <a href="qdatetime.html#toUTC">toUTC</a>() to convert it to UTC. You can
also use <a href="qdatetime.html#timeSpec">timeSpec</a>() to find
out if a QDateTime object stores a UTC time or a local time.
Operations such as <a href="qdatetime.html#addSecs">addSecs</a>()
and <a href="qdatetime.html#secsTo">secsTo</a>() are aware of
daylight saving time (DST).</p>
<p><b>Note:</b> QDateTime does not account for leap seconds.</p>
<a id="use-of-gregorian-and-julian-calendars" name="use-of-gregorian-and-julian-calendars" /> <a id="qdatetime-g-and-j" name="qdatetime-g-and-j" /><a id="use-of-gregorian-and-julian-calendars" name="use-of-gregorian-and-julian-calendars" />
<h4>Use of Gregorian and Julian Calendars</h4>
<p><a href="qdate.html">QDate</a> uses the Gregorian calendar in
all locales, beginning on the date 15 October 1582. For dates up to
and including 4 October 1582, the Julian calendar is used. This
means there is a 10-day gap in the internal calendar between the
4th and the 15th of October 1582. When you use QDateTime for dates
in that epoch, the day after 4 October 1582 is 15 October 1582, and
the dates in the gap are invalid.</p>
<p>The Julian to Gregorian changeover date used here is the date
when the Gregorian calendar was first introduced, by Pope Gregory
XIII. That change was not universally accepted and some localities
only executed it at a later date (if at all). QDateTime doesn't
take any of these historical facts into account. If an application
must support a locale-specific dating system, it must do so on its
own, remembering to convert the dates using the Julian day.</p>
<a id="no-year-0" name="no-year-0" />
<h4>No Year 0</h4>
<p>There is no year 0. Dates in that year are considered invalid.
The year -1 is the year "1 before Christ" or "1 before current
era." The day before 0001-01-01 is December 31st, 1 BCE.</p>
<a id="range-of-valid-dates" name="range-of-valid-dates" />
<h4>Range of Valid Dates</h4>
<p>The range of valid dates is from January 2nd, 4713 BCE, to
sometime in the year 11 million CE. The Julian Day returned by
<a href="qdate.html#toJulianDay">QDate.toJulianDay</a>() is a
number in the contiguous range from 1 to <i>overflow</i>, even
across QDateTime's "date holes". It is suitable for use in
applications that must convert a QDateTime to a date in another
calendar system, e.g., Hebrew, Islamic or Chinese.</p>
<p>The Gregorian calendar was introduced in different places around
the world on different dates. QDateTime uses <a href="qdate.html">QDate</a> to store the date, so it uses the Gregorian
calendar for all locales, beginning on the date 15 October 1582.
For dates up to and including 4 October 1582, QDateTime uses the
Julian calendar. This means there is a 10-day gap in the QDateTime
calendar between the 4th and the 15th of October 1582. When you use
QDateTime for dates in that epoch, the day after 4 October 1582 is
15 October 1582, and the dates in the gap are invalid.</p>
<a id="use-of-system-timezone" name="use-of-system-timezone" />
<h4>Use of System Timezone</h4>
<p>QDateTime uses the system's time zone information to determine
the offset of local time from UTC. If the system is not configured
correctly or not up-to-date, QDateTime will give wrong results as
well.</p>
<a id="daylight-savings-time-dst" name="daylight-savings-time-dst" />
<h4>Daylight Savings Time (DST)</h4>
<p>QDateTime takes into account the system's time zone information
when dealing with DST. On modern Unix systems, this means it
applies the correct historical DST data whenever possible. On
Windows and Windows CE, where the system doesn't support historical
DST data, historical accuracy is not maintained with respect to
DST.</p>
<p>The range of valid dates taking DST into account is 1970-01-01
to the present, and rules are in place for handling DST correctly
until 2037-12-31, but these could change. For dates falling outside
that range, QDateTime makes a <i>best guess</i> using the rules for
year 1970 or 2037, but we can't guarantee accuracy. This means
QDateTime doesn't take into account changes in a locale's time zone
before 1970, even if the system's time zone database supports that
information.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QDateTime" />QDateTime.__init__ (<i>self</i>)</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><b>See also</b> <a href="qdatetime.html#isValid">isValid</a>().</p>
<h3 class="fn"><a name="QDateTime-2" />QDateTime.__init__ (<i>self</i>, <a href="qdatetime.html">QDateTime</a> <i>other</i>)</h3><p>Constructs a datetime with the given <i>date</i>, a valid
time(00:00:00.000), and sets the <a href="qdatetime.html#timeSpec">timeSpec</a>() to <a href="qt.html#TimeSpec-enum">Qt.LocalTime</a>.</p>
<h3 class="fn"><a name="QDateTime-3" />QDateTime.__init__ (<i>self</i>, <a href="qdate.html">QDate</a>)</h3><p>Constructs a datetime with the given <i>date</i> and
<i>time</i>, using the time specification defined by
<i>spec</i>.</p>
<p>If <i>date</i> is valid and <i>time</i> is not, the time will be
set to midnight.</p>
<h3 class="fn"><a name="QDateTime-4" />QDateTime.__init__ (<i>self</i>, <a href="qdate.html">QDate</a> <i>date</i>, <a href="qtime.html">QTime</a> <i>time</i>, <a href="qt.html#TimeSpec-enum">Qt.TimeSpec</a> <i>timeSpec</i> = Qt.LocalTime)</h3><p>Constructs a copy of the <i>other</i> datetime.</p>
<h3 class="fn"><a name="QDateTime-5" />QDateTime.__init__ (<i>self</i>, int <i>y</i>, int <i>m</i>, int <i>d</i>, int <i>h</i>, int <i>m</i>, int <i>s</i> = 0, int <i>msec</i> = 0, int <i>timeSpec</i> = 0)</h3><h3 class="fn"><a name="addDays" /><a href="qdatetime.html">QDateTime</a> QDateTime.addDays (<i>self</i>, int <i>days</i>)</h3><p>Returns a <a href="qdatetime.html">QDateTime</a> object
containing a datetime <i>ndays</i> days later than the datetime of
this object (or earlier if <i>ndays</i> is negative).</p>
<p><b>See also</b> <a href="qdatetime.html#daysTo">daysTo</a>(),
<a href="qdatetime.html#addMonths">addMonths</a>(), <a href="qdatetime.html#addYears">addYears</a>(), and <a href="qdatetime.html#addSecs">addSecs</a>().</p>
<h3 class="fn"><a name="addMonths" /><a href="qdatetime.html">QDateTime</a> QDateTime.addMonths (<i>self</i>, int <i>months</i>)</h3><p>Returns a <a href="qdatetime.html">QDateTime</a> object
containing a datetime <i>nmonths</i> months later than the datetime
of this object (or earlier if <i>nmonths</i> is negative).</p>
<p><b>See also</b> <a href="qdatetime.html#daysTo">daysTo</a>(),
<a href="qdatetime.html#addDays">addDays</a>(), <a href="qdatetime.html#addYears">addYears</a>(), and <a href="qdatetime.html#addSecs">addSecs</a>().</p>
<h3 class="fn"><a name="addMSecs" /><a href="qdatetime.html">QDateTime</a> QDateTime.addMSecs (<i>self</i>, int <i>msecs</i>)</h3><p>Returns a <a href="qdatetime.html">QDateTime</a> object
containing a datetime <i>msecs</i> miliseconds later than the
datetime of this object (or earlier if <i>msecs</i> is
negative).</p>
<p><b>See also</b> <a href="qdatetime.html#addSecs">addSecs</a>(),
<a href="qdatetime.html#msecsTo">msecsTo</a>(), <a href="qdatetime.html#addDays">addDays</a>(), <a href="qdatetime.html#addMonths">addMonths</a>(), and <a href="qdatetime.html#addYears">addYears</a>().</p>
<h3 class="fn"><a name="addSecs" /><a href="qdatetime.html">QDateTime</a> QDateTime.addSecs (<i>self</i>, int <i>secs</i>)</h3><p>Returns a <a href="qdatetime.html">QDateTime</a> object
containing a datetime <i>s</i> seconds later than the datetime of
this object (or earlier if <i>s</i> is negative).</p>
<p><b>See also</b> <a href="qdatetime.html#addMSecs">addMSecs</a>(), <a href="qdatetime.html#secsTo">secsTo</a>(), <a href="qdatetime.html#addDays">addDays</a>(), <a href="qdatetime.html#addMonths">addMonths</a>(), and <a href="qdatetime.html#addYears">addYears</a>().</p>
<h3 class="fn"><a name="addYears" /><a href="qdatetime.html">QDateTime</a> QDateTime.addYears (<i>self</i>, int <i>years</i>)</h3><p>Returns a <a href="qdatetime.html">QDateTime</a> object
containing a datetime <i>nyears</i> years later than the datetime
of this object (or earlier if <i>nyears</i> is negative).</p>
<p><b>See also</b> <a href="qdatetime.html#daysTo">daysTo</a>(),
<a href="qdatetime.html#addDays">addDays</a>(), <a href="qdatetime.html#addMonths">addMonths</a>(), and <a href="qdatetime.html#addSecs">addSecs</a>().</p>
<h3 class="fn"><a name="currentDateTime" /><a href="qdatetime.html">QDateTime</a> QDateTime.currentDateTime ()</h3><p>Returns the current datetime, as reported by the system clock,
in the local time zone.</p>
<p><b>See also</b> <a href="qdatetime.html#currentDateTimeUtc">currentDateTimeUtc</a>(),
<a href="qdate.html#currentDate">QDate.currentDate</a>(), <a href="qtime.html#currentTime">QTime.currentTime</a>(), and <a href="qdatetime.html#toTimeSpec">toTimeSpec</a>().</p>
<h3 class="fn"><a name="currentDateTimeUtc" /><a href="qdatetime.html">QDateTime</a> QDateTime.currentDateTimeUtc ()</h3><p>Returns the current datetime, as reported by the system clock,
in UTC.</p>
<p>This function was introduced in Qt 4.7.</p>
<p><b>See also</b> <a href="qdatetime.html#currentDateTime">currentDateTime</a>(), <a href="qdate.html#currentDate">QDate.currentDate</a>(), <a href="qtime.html#currentTime">QTime.currentTime</a>(), and <a href="qdatetime.html#toTimeSpec">toTimeSpec</a>().</p>
<h3 class="fn"><a name="currentMSecsSinceEpoch" />int QDateTime.currentMSecsSinceEpoch ()</h3><p>Returns the number of milliseconds since 1970-01-01T00:00:00
Universal Coordinated Time. This number is like the POSIX time_t
variable, but expressed in milliseconds instead.</p>
<p>This function was introduced in Qt 4.7.</p>
<p><b>See also</b> <a href="qdatetime.html#currentDateTime">currentDateTime</a>(), <a href="qdatetime.html#currentDateTimeUtc">currentDateTimeUtc</a>(),
<a href="qdatetime.html#toTime_t">toTime_t</a>(), and <a href="qdatetime.html#toTimeSpec">toTimeSpec</a>().</p>
<h3 class="fn"><a name="date" /><a href="qdate.html">QDate</a> QDateTime.date (<i>self</i>)</h3><p>Returns the date part of the datetime.</p>
<p><b>See also</b> <a href="qdatetime.html#setDate">setDate</a>(),
<a href="qdatetime.html#time">time</a>(), and <a href="qdatetime.html#timeSpec">timeSpec</a>().</p>
<h3 class="fn"><a name="daysTo" />int QDateTime.daysTo (<i>self</i>, <a href="qdatetime.html">QDateTime</a>)</h3><p>Returns the number of days from this datetime to the
<i>other</i> datetime. If the <i>other</i> datetime is earlier than
this datetime, the value returned is negative.</p>
<p><b>See also</b> <a href="qdatetime.html#addDays">addDays</a>(),
<a href="qdatetime.html#secsTo">secsTo</a>(), and <a href="qdatetime.html#msecsTo">msecsTo</a>().</p>
<h3 class="fn"><a name="fromMSecsSinceEpoch" /><a href="qdatetime.html">QDateTime</a> QDateTime.fromMSecsSinceEpoch (int <i>msecs</i>)</h3><p>Returns a datetime whose date and time are the number of
milliseconds, <i>msecs</i>, that have passed since
1970-01-01T00:00:00.000, Coordinated Universal Time (<a href="qt.html#TimeSpec-enum">Qt.UTC</a>). On systems that do not
support time zones, the time will be set as if local time were
<a href="qt.html#TimeSpec-enum">Qt.UTC</a>.</p>
<p>Note that there are possible values for <i>msecs</i> that lie
outside the valid range of <a href="qdatetime.html">QDateTime</a>,
both negative and positive. The behavior of this function is
undefined for those values.</p>
<p>This function was introduced in Qt 4.7.</p>
<p><b>See also</b> <a href="qdatetime.html#toTime_t">toTime_t</a>()
and <a href="qdatetime.html#setTime_t">setTime_t</a>().</p>
<h3 class="fn"><a name="fromString" /><a href="qdatetime.html">QDateTime</a> QDateTime.fromString (QString <i>string</i>, <a href="qt.html#DateFormat-enum">Qt.DateFormat</a> <i>format</i> = Qt.TextDate)</h3><p>Returns the <a href="qdatetime.html">QDateTime</a> represented
by the <i>string</i>, using the <i>format</i> given, or an invalid
datetime if this is not possible.</p>
<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>
<h3 class="fn"><a name="fromString-2" /><a href="qdatetime.html">QDateTime</a> QDateTime.fromString (QString <i>s</i>, QString <i>format</i>)</h3><p>Returns the <a href="qdatetime.html">QDateTime</a> represented
by the <i>string</i>, using the <i>format</i> given, or an invalid
datetime if the string cannot be parsed.</p>
<p>These expressions may be used for the date part of the format
string:</p>
<table class="generic">
<thead>
<tr class="qt-style">
<th>Expression</th>
<th>Output</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>d</td>
<td>the day as number without a leading zero (1 to 31)</td>
</tr>
<tr class="even" valign="top">
<td>dd</td>
<td>the day as number with a leading zero (01 to 31)</td>
</tr>
<tr class="odd" valign="top">
<td>ddd</td>
<td>the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses
<a href="qdate.html#shortDayName">QDate.shortDayName</a>().</td>
</tr>
<tr class="even" valign="top">
<td>dddd</td>
<td>the long localized day name (e.g. 'Monday' to 'Sunday'). Uses
<a href="qdate.html#longDayName">QDate.longDayName</a>().</td>
</tr>
<tr class="odd" valign="top">
<td>M</td>
<td>the month as number without a leading zero (1-12)</td>
</tr>
<tr class="even" valign="top">
<td>MM</td>
<td>the month as number with a leading zero (01-12)</td>
</tr>
<tr class="odd" valign="top">
<td>MMM</td>
<td>the abbreviated localized month name (e.g. 'Jan' to 'Dec').
Uses <a href="qdate.html#shortMonthName">QDate.shortMonthName</a>().</td>
</tr>
<tr class="even" valign="top">
<td>MMMM</td>
<td>the long localized month name (e.g. 'January' to 'December').
Uses <a href="qdate.html#longMonthName">QDate.longMonthName</a>().</td>
</tr>
<tr class="odd" valign="top">
<td>yy</td>
<td>the year as two digit number (00-99)</td>
</tr>
<tr class="even" valign="top">
<td>yyyy</td>
<td>the year as four digit number</td>
</tr>
</table>
<p><b>Note:</b> Unlike the other version of this function, day and
month names must be given in the user's local language. It is only
possible to use the English names if the user's language is
English.</p>
<p>These expressions may be used for the time part of the format
string:</p>
<table class="generic">
<thead>
<tr class="qt-style">
<th>Expression</th>
<th>Output</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>h</td>
<td>the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM
display)</td>
</tr>
<tr class="even" valign="top">
<td>hh</td>
<td>the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM
display)</td>
</tr>
<tr class="odd" valign="top">
<td>H</td>
<td>the hour without a leading zero (0 to 23, even with AM/PM
display)</td>
</tr>
<tr class="even" valign="top">
<td>HH</td>
<td>the hour with a leading zero (00 to 23, even with AM/PM
display)</td>
</tr>
<tr class="odd" valign="top">
<td>m</td>
<td>the minute without a leading zero (0 to 59)</td>
</tr>
<tr class="even" valign="top">
<td>mm</td>
<td>the minute with a leading zero (00 to 59)</td>
</tr>
<tr class="odd" valign="top">
<td>s</td>
<td>the second without a leading zero (0 to 59)</td>
</tr>
<tr class="even" valign="top">
<td>ss</td>
<td>the second with a leading zero (00 to 59)</td>
</tr>
<tr class="odd" valign="top">
<td>z</td>
<td>the milliseconds without leading zeroes (0 to 999)</td>
</tr>
<tr class="even" valign="top">
<td>zzz</td>
<td>the milliseconds with leading zeroes (000 to 999)</td>
</tr>
<tr class="odd" valign="top">
<td>AP or A</td>
<td>interpret as an AM/PM time. <i>AP</i> must be either "AM" or
"PM".</td>
</tr>
<tr class="even" valign="top">
<td>ap or a</td>
<td>Interpret as an AM/PM time. <i>ap</i> must be either "am" or
"pm".</td>
</tr>
</table>
<p>All other input characters will be treated as text. Any sequence
of characters that are enclosed in singlequotes will also be
treated as text and not be used as an expression.</p>
<pre class="cpp">
<span class="type"><a href="qtime.html">QTime</a></span> time1 <span class="operator">=</span> <span class="type"><a href="qtime.html">QTime</a></span><span class="operator">.</span><a href="qdatetime.html#fromString">fromString</a>(<span class="string">"131"</span><span class="operator">,</span> <span class="string">"HHh"</span>);
<span class="comment">// time1 is 13:00:00</span>
<span class="type"><a href="qtime.html">QTime</a></span> time1 <span class="operator">=</span> <span class="type"><a href="qtime.html">QTime</a></span><span class="operator">.</span><a href="qdatetime.html#fromString">fromString</a>(<span class="string">"1apA"</span><span class="operator">,</span> <span class="string">"1amAM"</span>);
<span class="comment">// time1 is 01:00:00</span>
<span class="type"><a href="qdatetime.html">QDateTime</a></span> dateTime2 <span class="operator">=</span> <span class="type"><a href="qdatetime.html">QDateTime</a></span><span class="operator">.</span><a href="qdatetime.html#fromString">fromString</a>(<span class="string">"M1d1y9800:01:02"</span><span class="operator">,</span>
<span class="string">"'M'M'd'd'y'yyhh:mm:ss"</span>);
<span class="comment">// dateTime is 1 January 1998 00:01:02</span>
</pre>
<p>If the format is not satisfied an invalid <a href="qdatetime.html">QDateTime</a> is returned. The expressions that
don't have leading zeroes (d, M, h, m, s, z) will be greedy. This
means that they will use two digits even if this will put them
outside the range and/or leave too few digits for other
sections.</p>
<pre class="cpp">
<span class="type"><a href="qdatetime.html">QDateTime</a></span> dateTime <span class="operator">=</span> <span class="type"><a href="qdatetime.html">QDateTime</a></span><span class="operator">.</span><a href="qdatetime.html#fromString">fromString</a>(<span class="string">"130"</span><span class="operator">,</span> <span class="string">"Mm"</span>); <span class="comment">// invalid</span>
</pre>
<p>This could have meant 1 January 00:30.00 but the M will grab two
digits.</p>
<p>For any field that is not represented in the format the
following defaults are used:</p>
<table class="generic">
<thead>
<tr class="qt-style">
<th>Field</th>
<th>Default value</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>Year</td>
<td>1900</td>
</tr>
<tr class="even" valign="top">
<td>Month</td>
<td>1 (January)</td>
</tr>
<tr class="odd" valign="top">
<td>Day</td>
<td>1</td>
</tr>
<tr class="even" valign="top">
<td>Hour</td>
<td>0</td>
</tr>
<tr class="odd" valign="top">
<td>Minute</td>
<td>0</td>
</tr>
<tr class="even" valign="top">
<td>Second</td>
<td>0</td>
</tr>
</table>
<p>For example:</p>
<pre class="cpp">
<span class="type"><a href="qdatetime.html">QDateTime</a></span> dateTime <span class="operator">=</span> <span class="type"><a href="qdatetime.html">QDateTime</a></span><span class="operator">.</span><a href="qdatetime.html#fromString">fromString</a>(<span class="string">"1.30.1"</span><span class="operator">,</span> <span class="string">"M.d.s"</span>);
<span class="comment">// dateTime is January 30 in 1900 at 00:00:01.</span>
</pre>
<p><a href="qdatetime.html#toString">QDateTime.toString</a>()
<a href="qtime.html#toString">QTime.toString</a>()</p>
<p><b>See also</b> <a href="qdate.html#fromString">QDate.fromString</a>(), <a href="qtime.html#fromString">QTime.fromString</a>(), and <a href="qdate.html#toString">QDate.toString</a>().</p>
<h3 class="fn"><a name="fromTime_t" /><a href="qdatetime.html">QDateTime</a> QDateTime.fromTime_t (int <i>secsSince1Jan1970UTC</i>)</h3><p>Returns a datetime whose date and time are the number of
<i>seconds</i> that have passed since 1970-01-01T00:00:00,
Coordinated Universal Time (<a href="qt.html#TimeSpec-enum">Qt.UTC</a>). On systems that do not
support time zones, the time will be set as if local time were
<a href="qt.html#TimeSpec-enum">Qt.UTC</a>.</p>
<p>This function was introduced in Qt 4.2.</p>
<p><b>See also</b> <a href="qdatetime.html#toTime_t">toTime_t</a>()
and <a href="qdatetime.html#setTime_t">setTime_t</a>().</p>
<h3 class="fn"><a name="isNull" />bool QDateTime.isNull (<i>self</i>)</h3><p>Returns true if both the date and the time are null; otherwise
returns false. A null datetime is invalid.</p>
<p><b>See also</b> <a href="qdate.html#isNull">QDate.isNull</a>(),
<a href="qtime.html#isNull">QTime.isNull</a>(), and <a href="qdatetime.html#isValid">isValid</a>().</p>
<h3 class="fn"><a name="isValid" />bool QDateTime.isValid (<i>self</i>)</h3><p>Returns true if both the date and the time are valid; otherwise
returns false.</p>
<p><b>See also</b> <a href="qdate.html#isValid">QDate.isValid</a>() and <a href="qtime.html#isValid">QTime.isValid</a>().</p>
<h3 class="fn"><a name="msecsTo" />int QDateTime.msecsTo (<i>self</i>, <a href="qdatetime.html">QDateTime</a>)</h3><p>Returns the number of milliseconds from this datetime to the
<i>other</i> datetime. If the <i>other</i> datetime is earlier than
this datetime, the value returned is negative.</p>
<p>Before performing the comparison, the two datetimes are
converted to <a href="qt.html#TimeSpec-enum">Qt.UTC</a> to ensure
that the result is correct if one of the two datetimes has daylight
saving time (DST) and the other doesn't.</p>
<p>This function was introduced in Qt 4.7.</p>
<p><b>See also</b> <a href="qdatetime.html#addMSecs">addMSecs</a>(), <a href="qdatetime.html#daysTo">daysTo</a>(), and <a href="qtime.html#msecsTo">QTime.msecsTo</a>().</p>
<h3 class="fn"><a name="secsTo" />int QDateTime.secsTo (<i>self</i>, <a href="qdatetime.html">QDateTime</a>)</h3><p>Returns the number of seconds from this datetime to the
<i>other</i> datetime. If the <i>other</i> datetime is earlier than
this datetime, the value returned is negative.</p>
<p>Before performing the comparison, the two datetimes are
converted to <a href="qt.html#TimeSpec-enum">Qt.UTC</a> to ensure
that the result is correct if one of the two datetimes has daylight
saving time (DST) and the other doesn't.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qdatetime.html">QDateTime</a></span> now <span class="operator">=</span> <span class="type"><a href="qdatetime.html">QDateTime</a></span><span class="operator">.</span><a href="qdatetime.html#currentDateTime">currentDateTime</a>();
<span class="type"><a href="qdatetime.html">QDateTime</a></span> xmas(<span class="type"><a href="qdate.html">QDate</a></span>(now<span class="operator">.</span>date()<span class="operator">.</span>year()<span class="operator">,</span> <span class="number">12</span><span class="operator">,</span> <span class="number">25</span>)<span class="operator">,</span> <span class="type"><a href="qtime.html">QTime</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>));
<a href="qtcore.html#qDebug">qDebug</a>(<span class="string">"There are %d seconds to Christmas"</span><span class="operator">,</span> now<span class="operator">.</span>secsTo(xmas));
</pre>
<p><b>See also</b> <a href="qdatetime.html#addSecs">addSecs</a>(),
<a href="qdatetime.html#daysTo">daysTo</a>(), and <a href="qtime.html#secsTo">QTime.secsTo</a>().</p>
<h3 class="fn"><a name="setDate" />QDateTime.setDate (<i>self</i>, <a href="qdate.html">QDate</a> <i>date</i>)</h3><p>Sets the date part of this datetime to <i>date</i>. If no time
is set, it is set to midnight.</p>
<p><b>See also</b> <a href="qdatetime.html#date">date</a>(),
<a href="qdatetime.html#setTime">setTime</a>(), and <a href="qdatetime.html#setTimeSpec">setTimeSpec</a>().</p>
<h3 class="fn"><a name="setMSecsSinceEpoch" />QDateTime.setMSecsSinceEpoch (<i>self</i>, int <i>msecs</i>)</h3><p>Sets the date and time given the number of
milliseconds,<i>msecs</i>, that have passed since
1970-01-01T00:00:00.000, Coordinated Universal Time (<a href="qt.html#TimeSpec-enum">Qt.UTC</a>). On systems that do not
support time zones this function will behave as if local time were
<a href="qt.html#TimeSpec-enum">Qt.UTC</a>.</p>
<p>Note that there are possible values for <i>msecs</i> that lie
outside the valid range of <a href="qdatetime.html">QDateTime</a>,
both negative and positive. The behavior of this function is
undefined for those values.</p>
<p>This function was introduced in Qt 4.7.</p>
<p><b>See also</b> <a href="qdatetime.html#toMSecsSinceEpoch">toMSecsSinceEpoch</a>() and
<a href="qdatetime.html#setTime_t">setTime_t</a>().</p>
<h3 class="fn"><a name="setTime" />QDateTime.setTime (<i>self</i>, <a href="qtime.html">QTime</a> <i>time</i>)</h3><p>Sets the time part of this datetime to <i>time</i>.</p>
<p><b>See also</b> <a href="qdatetime.html#time">time</a>(),
<a href="qdatetime.html#setDate">setDate</a>(), and <a href="qdatetime.html#setTimeSpec">setTimeSpec</a>().</p>
<h3 class="fn"><a name="setTime_t" />QDateTime.setTime_t (<i>self</i>, int <i>secsSince1Jan1970UTC</i>)</h3><p>Sets the date and time given the number of <i>seconds</i> that
have passed since 1970-01-01T00:00:00, Coordinated Universal Time
(<a href="qt.html#TimeSpec-enum">Qt.UTC</a>). On systems that do
not support time zones this function will behave as if local time
were <a href="qt.html#TimeSpec-enum">Qt.UTC</a>.</p>
<p><b>See also</b> <a href="qdatetime.html#toTime_t">toTime_t</a>().</p>
<h3 class="fn"><a name="setTimeSpec" />QDateTime.setTimeSpec (<i>self</i>, <a href="qt.html#TimeSpec-enum">Qt.TimeSpec</a> <i>spec</i>)</h3><p>Sets the time specification used in this datetime to
<i>spec</i>.</p>
<p><b>See also</b> <a href="qdatetime.html#timeSpec">timeSpec</a>(), <a href="qdatetime.html#setDate">setDate</a>(), <a href="qdatetime.html#setTime">setTime</a>(), and <a href="qt.html#TimeSpec-enum">Qt.TimeSpec</a>.</p>
<h3 class="fn"><a name="time" /><a href="qtime.html">QTime</a> QDateTime.time (<i>self</i>)</h3><p>Returns the time part of the datetime.</p>
<p><b>See also</b> <a href="qdatetime.html#setTime">setTime</a>(),
<a href="qdatetime.html#date">date</a>(), and <a href="qdatetime.html#timeSpec">timeSpec</a>().</p>
<h3 class="fn"><a name="timeSpec" /><a href="qt.html#TimeSpec-enum">Qt.TimeSpec</a> QDateTime.timeSpec (<i>self</i>)</h3><p>Returns the time specification of the datetime.</p>
<p><b>See also</b> <a href="qdatetime.html#setTimeSpec">setTimeSpec</a>(), <a href="qdatetime.html#date">date</a>(), <a href="qdatetime.html#time">time</a>(), and <a href="qt.html#TimeSpec-enum">Qt.TimeSpec</a>.</p>
<h3 class="fn"><a name="toLocalTime" /><a href="qdatetime.html">QDateTime</a> QDateTime.toLocalTime (<i>self</i>)</h3><p>Returns a datetime containing the date and time information in
this datetime, but specified using the <a href="qt.html#TimeSpec-enum">Qt.LocalTime</a> definition.</p>
<p><b>See also</b> <a href="qdatetime.html#toTimeSpec">toTimeSpec</a>().</p>
<h3 class="fn"><a name="toMSecsSinceEpoch" />int QDateTime.toMSecsSinceEpoch (<i>self</i>)</h3><p>Returns the datetime as the number of milliseconds that have
passed since 1970-01-01T00:00:00.000, Coordinated Universal Time
(<a href="qt.html#TimeSpec-enum">Qt.UTC</a>).</p>
<p>On systems that do not support time zones, this function will
behave as if local time were <a href="qt.html#TimeSpec-enum">Qt.UTC</a>.</p>
<p>The behavior for this function is undefined if the datetime
stored in this object is not valid. However, for all valid dates,
this function returns a unique value.</p>
<p>This function was introduced in Qt 4.7.</p>
<p><b>See also</b> <a href="qdatetime.html#toTime_t">toTime_t</a>()
and <a href="qdatetime.html#setMSecsSinceEpoch">setMSecsSinceEpoch</a>().</p>
<h3 class="fn"><a name="toPyDateTime" />datetime.datetime QDateTime.toPyDateTime (<i>self</i>)</h3><h3 class="fn"><a name="toString" />QString QDateTime.toString (<i>self</i>, <a href="qt.html#DateFormat-enum">Qt.DateFormat</a> <i>format</i> = Qt.TextDate)</h3><p>Returns the datetime as a string. The <i>format</i> parameter
determines the format of the result string.</p>
<p>These expressions may be used for the date:</p>
<table class="generic">
<thead>
<tr class="qt-style">
<th>Expression</th>
<th>Output</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>d</td>
<td>the day as number without a leading zero (1 to 31)</td>
</tr>
<tr class="even" valign="top">
<td>dd</td>
<td>the day as number with a leading zero (01 to 31)</td>
</tr>
<tr class="odd" valign="top">
<td>ddd</td>
<td>the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses
<a href="qdate.html#shortDayName">QDate.shortDayName</a>().</td>
</tr>
<tr class="even" valign="top">
<td>dddd</td>
<td>the long localized day name (e.g. 'Monday' to '<a href="qt.html#DayOfWeek-enum">Qt.Sunday</a>'). Uses <a href="qdate.html#longDayName">QDate.longDayName</a>().</td>
</tr>
<tr class="odd" valign="top">
<td>M</td>
<td>the month as number without a leading zero (1-12)</td>
</tr>
<tr class="even" valign="top">
<td>MM</td>
<td>the month as number with a leading zero (01-12)</td>
</tr>
<tr class="odd" valign="top">
<td>MMM</td>
<td>the abbreviated localized month name (e.g. 'Jan' to 'Dec').
Uses <a href="qdate.html#shortMonthName">QDate.shortMonthName</a>().</td>
</tr>
<tr class="even" valign="top">
<td>MMMM</td>
<td>the long localized month name (e.g. 'January' to 'December').
Uses <a href="qdate.html#longMonthName">QDate.longMonthName</a>().</td>
</tr>
<tr class="odd" valign="top">
<td>yy</td>
<td>the year as two digit number (00-99)</td>
</tr>
<tr class="even" valign="top">
<td>yyyy</td>
<td>the year as four digit number</td>
</tr>
</table>
<p>These expressions may be used for the time:</p>
<table class="generic">
<thead>
<tr class="qt-style">
<th>Expression</th>
<th>Output</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>h</td>
<td>the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM
display)</td>
</tr>
<tr class="even" valign="top">
<td>hh</td>
<td>the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM
display)</td>
</tr>
<tr class="odd" valign="top">
<td>m</td>
<td>the minute without a leading zero (0 to 59)</td>
</tr>
<tr class="even" valign="top">
<td>mm</td>
<td>the minute with a leading zero (00 to 59)</td>
</tr>
<tr class="odd" valign="top">
<td>s</td>
<td>the second without a leading zero (0 to 59)</td>
</tr>
<tr class="even" valign="top">
<td>ss</td>
<td>the second with a leading zero (00 to 59)</td>
</tr>
<tr class="odd" valign="top">
<td>z</td>
<td>the milliseconds without leading zeroes (0 to 999)</td>
</tr>
<tr class="even" valign="top">
<td>zzz</td>
<td>the milliseconds with leading zeroes (000 to 999)</td>
</tr>
<tr class="odd" valign="top">
<td>AP</td>
<td>use AM/PM display. <i>AP</i> will be replaced by either "AM" or
"PM".</td>
</tr>
<tr class="even" valign="top">
<td>ap</td>
<td>use am/pm display. <i>ap</i> will be replaced by either "am" or
"pm".</td>
</tr>
</table>
<p>All other input characters will be ignored. Any sequence of
characters that are enclosed in singlequotes will be treated as
text and not be used as an expression. Two consecutive singlequotes
("''") are replaced by a singlequote in the output.</p>
<p>Example format strings (assumed that the <a href="qdatetime.html">QDateTime</a> is 21 May 2001 14:13:09):</p>
<table class="generic">
<thead>
<tr class="qt-style">
<th>Format</th>
<th>Result</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>dd.MM.yyyy</td>
<td>21.05.2001</td>
</tr>
<tr class="even" valign="top">
<td>ddd MMMM d yy</td>
<td>Tue May 21 01</td>
</tr>
<tr class="odd" valign="top">
<td>hh:mm:ss.zzz</td>
<td>14:13:09.042</td>
</tr>
<tr class="even" valign="top">
<td>h:m:s ap</td>
<td>2:13:9 pm</td>
</tr>
</table>
<p>If the datetime is invalid, an empty string will be
returned.</p>
<p><b>See also</b> <a href="qdate.html#toString">QDate.toString</a>() and <a href="qtime.html#toString">QTime.toString</a>().</p>
<h3 class="fn"><a name="toString-2" />QString QDateTime.toString (<i>self</i>, QString <i>format</i>)</h3><p>This is an overloaded function.</p>
<p>Returns the datetime as a string in the <i>format</i> given.</p>
<p>If the <i>format</i> is <a href="qt.html#DateFormat-enum">Qt.TextDate</a>, the string is formatted
in the default way. <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>() are used to
generate the string, so the day and month names will be localized
names. An example of this formatting is "Wed May 20 03:40:13
1998".</p>
<p>If the <i>format</i> 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, taking the form
YYYY-MM-DDTHH:mm:ss[Z|[+|-]HH:mm], depending on the <a href="qdatetime.html#timeSpec">timeSpec</a>() of the <a href="qdatetime.html">QDateTime</a>. If the <a href="qdatetime.html#timeSpec">timeSpec</a>() is <a href="qt.html#TimeSpec-enum">Qt.UTC</a>, Z will be appended to the
string; if the <a href="qdatetime.html#timeSpec">timeSpec</a>() is
<a href="qt.html#TimeSpec-enum">Qt.OffsetFromUTC</a> the offset in
hours and minutes from UTC will be appended to the string.</p>
<p>If the <i>format</i> is <a href="qt.html#DateFormat-enum">Qt.SystemLocaleShortDate</a> or <a href="qt.html#DateFormat-enum">Qt.SystemLocaleLongDate</a>, the string
format depends on the locale settings of the system. Identical to
calling <a href="qlocale.html#system">QLocale.system</a>().toString(datetime,
<a href="qlocale.html#FormatType-enum">QLocale.ShortFormat</a>) or
<a href="qlocale.html#system">QLocale.system</a>().toString(datetime,
<a href="qlocale.html#FormatType-enum">QLocale.LongFormat</a>).</p>
<p>If the <i>format</i> is <a href="qt.html#DateFormat-enum">Qt.DefaultLocaleShortDate</a> or
<a href="qt.html#DateFormat-enum">Qt.DefaultLocaleLongDate</a>,
the string format depends on the default application locale. This
is the locale set with <a href="qlocale.html#setDefault">QLocale.setDefault</a>(), or the system
locale if no default locale has been set. Identical to calling
QLocale().toString(datetime, <a href="qlocale.html#FormatType-enum">QLocale.ShortFormat</a>) or
QLocale().toString(datetime, <a href="qlocale.html#FormatType-enum">QLocale.LongFormat</a>).</p>
<p>If the datetime is invalid, an empty string will be
returned.</p>
<p><b>Warning:</b> The <a href="qt.html#DateFormat-enum">Qt.ISODate</a> format is only valid for
years in the range 0 to 9999. This restriction may apply to
locale-aware formats as well, depending on the locale settings.</p>
<p><b>See also</b> <a href="qdate.html#toString">QDate.toString</a>(), <a href="qtime.html#toString">QTime.toString</a>(), and <a href="qt.html#DateFormat-enum">Qt.DateFormat</a>.</p>
<h3 class="fn"><a name="toTime_t" />int QDateTime.toTime_t (<i>self</i>)</h3><p>Returns the datetime as the number of seconds that have passed
since 1970-01-01T00:00:00, Coordinated Universal Time (<a href="qt.html#TimeSpec-enum">Qt.UTC</a>).</p>
<p>On systems that do not support time zones, this function will
behave as if local time were <a href="qt.html#TimeSpec-enum">Qt.UTC</a>.</p>
<p><b>Note:</b> This function returns a 32-bit unsigned integer, so
it does not support dates before 1970, but it does support dates
after 2038-01-19T03:14:06, which may not be valid time_t values. Be
careful when passing those time_t values to system functions, which
could interpret them as negative dates.</p>
<p>If the date is outside the range 1970-01-01T00:00:00 to
2106-02-07T06:28:14, this function returns -1 cast to an unsigned
integer (i.e., 0xFFFFFFFF).</p>
<p>To get an extended range, use <a href="qdatetime.html#toMSecsSinceEpoch">toMSecsSinceEpoch</a>().</p>
<p><b>See also</b> <a href="qdatetime.html#toMSecsSinceEpoch">toMSecsSinceEpoch</a>() and
<a href="qdatetime.html#setTime_t">setTime_t</a>().</p>
<h3 class="fn"><a name="toTimeSpec" /><a href="qdatetime.html">QDateTime</a> QDateTime.toTimeSpec (<i>self</i>, <a href="qt.html#TimeSpec-enum">Qt.TimeSpec</a> <i>spec</i>)</h3><p>Returns a copy of this datetime configured to use the given time
<i>specification</i>.</p>
<p><b>See also</b> <a href="qdatetime.html#timeSpec">timeSpec</a>(), <a href="qdatetime.html#toUTC">toUTC</a>(), and <a href="qdatetime.html#toLocalTime">toLocalTime</a>().</p>
<h3 class="fn"><a name="toUTC" /><a href="qdatetime.html">QDateTime</a> QDateTime.toUTC (<i>self</i>)</h3><p>Returns a datetime containing the date and time information in
this datetime, but specified using the <a href="qt.html#TimeSpec-enum">Qt.UTC</a> definition.</p>
<p><b>See also</b> <a href="qdatetime.html#toTimeSpec">toTimeSpec</a>().</p>
<h3 class="fn"><a name="__bool__" />int QDateTime.__bool__ (<i>self</i>)</h3><h3 class="fn"><a name="__eq__" />bool QDateTime.__eq__ (<i>self</i>, <a href="qdatetime.html">QDateTime</a> <i>other</i>)</h3><h3 class="fn"><a name="__ge__" />bool QDateTime.__ge__ (<i>self</i>, <a href="qdatetime.html">QDateTime</a> <i>other</i>)</h3><h3 class="fn"><a name="__gt__" />bool QDateTime.__gt__ (<i>self</i>, <a href="qdatetime.html">QDateTime</a> <i>other</i>)</h3><h3 class="fn"><a name="__hash__" />int QDateTime.__hash__ (<i>self</i>)</h3><h3 class="fn"><a name="__le__" />bool QDateTime.__le__ (<i>self</i>, <a href="qdatetime.html">QDateTime</a> <i>other</i>)</h3><h3 class="fn"><a name="__lt__" />bool QDateTime.__lt__ (<i>self</i>, <a href="qdatetime.html">QDateTime</a> <i>other</i>)</h3><h3 class="fn"><a name="__ne__" />bool QDateTime.__ne__ (<i>self</i>, <a href="qdatetime.html">QDateTime</a> <i>other</i>)</h3><h3 class="fn"><a name="__repr__" />str QDateTime.__repr__ (<i>self</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.11.4 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qt.io">The Qt Company</a> 2015</td><td align="right" width="25%">Qt 4.8.7</td></tr></table></div></address></body></html>
|