<?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[Core2 RTC adjusting for DST]]></title><description><![CDATA[<p dir="auto">I'd like to have the time automatically adjust for Daylight Saving time without having ge an NTP update.<br />
The following code sets my timezone and DST correctly when it does an NTP update. But if I explicitly set the time and date to just before a DST change and observe  the time, it doesn't change to the DST time.<br />
I'd be grateful for any observations and suggesions.</p>
<p dir="auto">bool timeSync() {<br />
configTime(0, 0, ntpServer);  // get UTC time from NTP server<br />
setenv("TZ", timezone, 1);  //  Set the TZ.<br />
tzset();<br />
if (!getLocalTime(&amp;timeinfo)) {<br />
Serial.print("Failed to obtain time from ");<br />
Serial.println(ntpServer);<br />
return false;<br />
}<br />
// Copy the time and date from the struct tm format into the M5Core2<br />
// TimeStruct and write it into the RTC.<br />
TimeStruct.Hours = timeinfo.tm_hour;<br />
TimeStruct.Minutes = timeinfo.tm_min;<br />
TimeStruct.Seconds = timeinfo.tm_sec;<br />
DateStruct.Year = (timeinfo.tm_year + 1900);<br />
DateStruct.Month = (timeinfo.tm_mon + 1);<br />
DateStruct.Date = timeinfo.tm_mday;<br />
DateStruct.WeekDay = timeinfo.tm_wday;  // day of week. 0 = Sunday</p>
<p dir="auto">//      TimeStruct.Hours = 2;<br />
//      TimeStruct.Minutes = 58;<br />
//      DateStruct.Month = 4;<br />
//      DateStruct.Date = 3;<br />
//      DateStruct.WeekDay = 0;<br />
M5.Rtc.SetTime(&amp;TimeStruct);<br />
M5.Rtc.SetDate(&amp;DateStruct);</p>
<p dir="auto">return true;<br />
}</p>
]]></description><link>https://community.m5stack.com/topic/4312/core2-rtc-adjusting-for-dst</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 22:34:23 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/4312.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 23 May 2022 07:12:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Core2 RTC adjusting for DST on Wed, 08 Jun 2022 07:01:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chriszang" aria-label="Profile: ChrisZang">@<bdi>ChrisZang</bdi></a> thanks for the reply.<br />
The problem is that will only set up the time and DST offset if I request the time from the NTP server. When a DST transition occurs sometime later the clock will not automatically adjust without doing another request from the NTP server.<br />
I have solved the problem by simply adding the code to advance or retard the clock at the appropriate time based on my timezone. i.e. first Sunday in April at 03:00 I change the clock to 02:00 and the first Sunday in October at 02:00 I change the clock to 03:00.</p>
]]></description><link>https://community.m5stack.com/post/17671</link><guid isPermaLink="true">https://community.m5stack.com/post/17671</guid><dc:creator><![CDATA[johno]]></dc:creator><pubDate>Wed, 08 Jun 2022 07:01:00 GMT</pubDate></item><item><title><![CDATA[Reply to Core2 RTC adjusting for DST on Mon, 06 Jun 2022 20:55:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/johno" aria-label="Profile: johno">@<bdi>johno</bdi></a> try this:</p>
<p dir="auto">#include "time.h"</p>
<p dir="auto">// Set offset time in seconds to adjust for your timezone, for example:<br />
#define GMT+1 3600<br />
#define GMT+8 28800<br />
#define GMT-1 -3600<br />
#define GMT0 0<br />
#define PST -28800<br />
#define DST 3600</p>
<p dir="auto">// this sets the timezone to PT with automatic switch for DST<br />
const char* ntpServer = "<a href="http://pool.ntp.org" target="_blank" rel="noopener noreferrer nofollow ugc">pool.ntp.org</a>";<br />
const long  gmtOffset_sec = PST;<br />
const int   daylightOffset_sec = DST;</p>
<p dir="auto">void (setup ()<br />
{<br />
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);<br />
SetRTC() ;<br />
}</p>
<p dir="auto">bool SetRTC()<br />
{<br />
struct tm timeinfo;<br />
if(!getLocalTime(&amp;timeinfo))<br />
{<br />
Serial.println("Failed to obtain time");<br />
return (false);<br />
}<br />
RTCtime.Hours = timeinfo.tm_hour;<br />
RTCtime.Minutes = timeinfo.tm_min;<br />
RTCtime.Seconds = timeinfo.tm_sec;<br />
RTCDate.Year = timeinfo.tm_year+1900;<br />
RTCDate.Month = timeinfo.tm_mon;<br />
RTCDate.Date = timeinfo.tm_mday;<br />
return (true);<br />
}</p>
]]></description><link>https://community.m5stack.com/post/17668</link><guid isPermaLink="true">https://community.m5stack.com/post/17668</guid><dc:creator><![CDATA[ChrisZang]]></dc:creator><pubDate>Mon, 06 Jun 2022 20:55:27 GMT</pubDate></item></channel></rss>