<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QDateTime::currentDateTime timezone issue ?]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I am currently have a real strange issue with QDateTime::currentDatetime that I cannot comprehend.</p>
<p dir="auto">We have some code in Qt 5.12 we are porting to Qt 6.9.3. We are developping for Windows using MSVC2019.</p>
<p dir="auto">The code uses <code>QDateTime::currentDatetime()</code>. This worked fine in Qt 5.12 but in Qt 6.9.3 I have a 3 hour offset on my machine (this doesn't happen to my coworkers).</p>
<p dir="auto">I can fix this issue by sending the proper timezone to currentDateTime but when debugging it looks like currentDateTime already uses the right timezone:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/aa574bdc-2d26-4eb8-b34d-14a27437ed9c.png" alt="14eec021-6988-4712-82ec-c777bb2cf0c1-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">I've been trying to understand what the issue could be, if there is anything I may have done wrong, but I have absolutely no clue of what is happening here.</p>
<p dir="auto">Is this a known issue, have I made a mistake or is there something weird happening here ?</p>
]]></description><link>https://forum.qt.io/topic/165116/qdatetime-currentdatetime-timezone-issue</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 10:37:11 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/165116.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 24 Sep 2026 14:08:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QDateTime::currentDateTime timezone issue ? on Fri, 25 Sep 2026 09:37:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/f222">@<bdi>f222</bdi></a><br />
Two very quick checks to eliminate, which may be irrelevant:</p>
<ul>
<li>Does your machine/user have any <code>TZ</code> environment variable set?</li>
<li>Does your Registry have <code>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation</code> and is it same as other users?</li>
</ul>
]]></description><link>https://forum.qt.io/post/840264</link><guid isPermaLink="true">https://forum.qt.io/post/840264</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 25 Sep 2026 09:37:57 GMT</pubDate></item><item><title><![CDATA[Reply to QDateTime::currentDateTime timezone issue ? on Fri, 25 Sep 2026 09:19:23 GMT]]></title><description><![CDATA[<p dir="auto">I've been doing some more tests and its getting even weirder:</p>
<ul>
<li>Added QCoreApplication instanciation</li>
<li>Updated Qt version (same result with Qt 6.11.2 and 6.12.0 rc)</li>
</ul>
<p dir="auto">From what I see now:</p>
<ul>
<li>Systemtime is correct UTC</li>
<li>LocalTime is my OS displayed time</li>
<li>When getting a currentDateTime from a timezone build with Qt::localTime the timezones seem to be different but I'm getting the same time</li>
<li>When getting a currentDateTime from a timeZone build with systemTimezone the timezones seem to be equal but I'm getting a different time</li>
</ul>
<p dir="auto">I'm going to open a ticket but since the issue is only happening on my machine I think there must be something weird somewhere else 🤔</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/04870fab-7fc3-4818-baec-7fc0c9c37524.png" alt="image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/840263</link><guid isPermaLink="true">https://forum.qt.io/post/840263</guid><dc:creator><![CDATA[f222]]></dc:creator><pubDate>Fri, 25 Sep 2026 09:19:23 GMT</pubDate></item><item><title><![CDATA[Reply to QDateTime::currentDateTime timezone issue ? on Fri, 25 Sep 2026 08:41:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/f222">@<bdi>f222</bdi></a><br />
I have a quite different platform/environment from you: Qt 6.10.2 as supplied with Ubuntu 26.04, <strong>gcc</strong> compiler.  I confirm your code works <em>correctly</em> for me --- perhaps not surprisingly since you say yours does not happen to coworkers.</p>
<p dir="auto">Btw, I thought initially the lack of <code>QCoreApplication</code> might affect it, but I tried mine with and without and it made no difference (still correct).  You might just put one in in case it affects your situation.</p>
<p dir="auto">From <a href="https://codebrowser.dev/qt6/qtbase/src/corelib/time/qdatetime.cpp.html#_ZN9QDateTime15currentDateTimeERK9QTimeZone" target="_blank" rel="noopener noreferrer nofollow ugc">https://codebrowser.dev/qt6/qtbase/src/corelib/time/qdatetime.cpp.html#_ZN9QDateTime15currentDateTimeERK9QTimeZone</a> the definition of <a href="https://doc.qt.io/qt-6/qdatetime.html#currentDateTime" target="_blank" rel="noopener noreferrer nofollow ugc">QDateTime QDateTime::currentDateTime(const QTimeZone &amp;zone)</a> introduced at Qt 6.5 reads:</p>
<pre><code class="language-cpp">QDateTime QDateTime::currentDateTime(const QTimeZone &amp;zone)
{
    return fromMSecsSinceEpoch(currentMSecsSinceEpoch(), zone);
}
</code></pre>
<p dir="auto">while the <a href="https://codebrowser.dev/qt6/qtbase/src/corelib/time/qdatetime.cpp.html#_ZN9QDateTime15currentDateTimeEv" target="_blank" rel="noopener noreferrer nofollow ugc">overload without parameter</a> is:</p>
<pre><code class="language-cpp">QDateTime QDateTime::currentDateTime()
{
    return currentDateTime(QTimeZone::LocalTime);
}
</code></pre>
<p dir="auto">Knowing this you might want to investigate a bit further why they are giving you different results in your environment and find where the underlying odd behaviour is coming from.</p>
]]></description><link>https://forum.qt.io/post/840261</link><guid isPermaLink="true">https://forum.qt.io/post/840261</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 25 Sep 2026 08:41:26 GMT</pubDate></item><item><title><![CDATA[Reply to QDateTime::currentDateTime timezone issue ? on Fri, 25 Sep 2026 08:37:56 GMT]]></title><description><![CDATA[<p dir="auto">Please use a recent Qt version. Also you forgot to create a Q(Core)Application object. This works fine for me with Qt 6.12 (git HEAD):</p>
<pre><code>int main(int argc, char** argv)
{
    QCoreApplication app(argc, argv);
    qDebug() &lt;&lt; QDateTime::currentDateTime().timeZone();
    qDebug() &lt;&lt; QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss");
    qDebug() &lt;&lt; QTimeZone::systemTimeZone();
    qDebug() &lt;&lt; QDateTime::currentDateTime(QTimeZone::systemTimeZone()).toString("dd/MM/yyyy hh:mm:ss");
    return 0;
}
QTimeZone("Europe/Berlin")
"25/09/2026 10:37:14"
QTimeZone("Europe/Berlin")
"25/09/2026 10:37:14"

</code></pre>
]]></description><link>https://forum.qt.io/post/840260</link><guid isPermaLink="true">https://forum.qt.io/post/840260</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Fri, 25 Sep 2026 08:37:56 GMT</pubDate></item><item><title><![CDATA[Reply to QDateTime::currentDateTime timezone issue ? on Fri, 25 Sep 2026 07:57:32 GMT]]></title><description><![CDATA[<p dir="auto">Looks like a bug, consider reporting it (but maybe first check with newest Qt version, perhaps it has already been fixed?).</p>
]]></description><link>https://forum.qt.io/post/840259</link><guid isPermaLink="true">https://forum.qt.io/post/840259</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Fri, 25 Sep 2026 07:57:32 GMT</pubDate></item></channel></rss>