diff options
author | Mitch Curtis <mitch.curtis@nokia.com> | 2012-09-03 15:26:39 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-09-03 15:58:08 +0200 |
commit | 1b4ab3764b989958109913ba59b0bc9a95aed6f2 (patch) | |
tree | 8ef2916af425912ad3fabcc5f140a244bece00d0 /src/corelib/doc/snippets | |
parent | c9819493d3d5697929b3aa09accb6cea0be10396 (diff) |
Clarify QDateTime documentation re timeSpec conversion.
Clarify the documentation for setTimeSpec, toTimeSpec, toUTC and
toLocalTime, to be clear on which ones return the same point in time,
and which one simply changes the timezone.
Change-Id: Ic47dd8876ea733f1df0f64eca5bdf00d04f8d0d4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/doc/snippets')
-rw-r--r-- | src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp index ce0ccc12f4..1a89d4d5aa 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp @@ -156,4 +156,39 @@ qDebug() << "Days from startDate to endDate: " << startDate.daysTo(endDate); qSwap(startDate, endDate); // Make endDate before startDate. qDebug() << "Days from startDate to endDate: " << startDate.daysTo(endDate); -//! [15]
\ No newline at end of file +//! [15] + +//! [16] +QDateTime local(QDateTime::currentDateTime()); +QDateTime UTC(local.toTimeSpec(Qt::UTC)); +qDebug() << "Local time is:" << local; +qDebug() << "UTC time is:" << UTC; +qDebug() << "No difference between times:" << local.secsTo(UTC); +//! [16] + +//! [17] +QDateTime UTC(QDateTime::currentDateTimeUtc()); +QDateTime local(UTC.toLocalTime()); +qDebug() << "UTC time is:" << UTC; +qDebug() << "Local time is:" << local; +qDebug() << "No difference between times:" << UTC.secsTo(local); +//! [17] + +//! [18] +QDateTime local(QDateTime::currentDateTime()); +QDateTime UTC(local.toUTC()); +qDebug() << "Local time is:" << local; +qDebug() << "UTC time is:" << UTC; +qDebug() << "No difference between times:" << local.secsTo(UTC); +//! [18] + +//! [19] +QDateTime local(QDateTime::currentDateTime()); +qDebug() << "Local time is:" << local; + +QDateTime UTC(local); +UTC.setTimeSpec(Qt::UTC); +qDebug() << "UTC time is:" << UTC; + +qDebug() << "There are" << local.secsTo(UTC) << "seconds difference between the datetimes."; +//! [19]
\ No newline at end of file |