NTPClient
NTPClient copied to clipboard
Question: Is there a way to set the time offset automatically
I live in an area with Daylight Saving and thus the time offset changes twice a year at different dates each years. I was wondering how one could automatise the changes.
NTP itself can't handle timezones nor daylight saving times. That's normally the job of the operating system.
What you can do, however, since the daylight savings occur in specific period of time (october 15 to february 17 here) you can just validate the output the DD/MM and adjust the offset accordingly.
Or you can just use the Timezone library.
I've tried using the TimeOffset parameter in both Constructor and setTimeOffset(). Both does NOT work :( It still outputs the same time (GMT-2, I think)
Some time ago i looked at "Arduino weather station/colour" which used time zone library. Perhaps this will provide what you need...google 'arduino weather station time zone'
On Sun, Jun 24, 2018, 16:39 jagganath69 [email protected] wrote:
I've tried using the TimeOffset parameter in both Constructor and setTimeOffset(). Both does NOT work :( It still outputs the same time (GMT-2, I think)
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/arduino-libraries/NTPClient/issues/40#issuecomment-399733580, or mute the thread https://github.com/notifications/unsubscribe-auth/AC_Oka0Jex6TBvDZ-Gilza2Jc4s62RoVks5t_zQggaJpZM4PZ7uN .
This may help. This function looks for the last sunday of a month and returns the utc. You may refine it for the correct hour that the change occurs. E.g. here the change is on the last sunday of march and the last sunday of october. Call the function twice for march and october and if the real time falls between the two, it is summer. BTW: dow() returns day of week as an integer between 0 and 6 inclusive, for the array 'sun','mon', 'tue' etc... weekday() would probably also work, but starts from 1. Disclaimer: I took this from my code, but cobbled a bit to make it understandable, YMMV.
t=now(); time_t llz=laatstezondag(3,31,year()); time_t hlz=laatstezondag(10,31,year()); if ((t>llz) && (t<hlz)) zomer=1; else zomer=0;
...
time_t laatstezondag(int maand,int dag,int jaar)
{ time_t nu,lz;
char w_dag[4]="xxx";
nu=now();
while ((strcmp(w_dag,"sun")) && (dag>24))
{
setTime(2, 0, 0, dag--, maand, jaar);
strcpy(w_dag,weekdag[dow(now())]);
lz=now();
}
setTime(nu);
return lz;
}
Windows 10 cannot do it either. So, fix it yourself and good luck.