I've a datalogger (mega2560 and ethernet/sd shield).
I've been able to sync the arduino time with a NTP server.
But an NTP server always gives UTC time. And I need local time.
Is there a module/code to convert the UTC to local, based on a timezone, keep in track with summertime ?
To write is self it nasty (summertime start at the last saturday of march and ends at the last saterday of oktober).
I may be misunderstanding your question/needs - but if you have a server that is synced to NTP, presumably it also has on it (or can be configured) to output "local time". Assuming the server is under your control, of course. So - can't you set a machine on your local network that gives you this information (I would think a simple linux box could easily do it - and for free)...?
I have myself no server, and I want to sync the arduino time with a timeserver on internet (fe NTP), but I need for arduino local with summertime.
Jeroen.
I see in your code:
Adjust timezone and DST... in my case add two hours
You just add 2 hours. What about if the DST changes. I would like to see this automatic change in code. But it is calender related (DST changes time in Europe the last sunday of the month oktober and back the last sunday of march...)
As far as I have searched I found no algorithm for DST. It differs per country / continent and if you read - Daylight saving time - Wikipedia - you see it is not easy.
In an application I made the logging had two timestamps, UTC for computers and a local time for humans. UTC will never shift (OK lapseconds not counted) No strange bumps/lines/jumps in Excel etc.
However if you find a good solution keep us informed!
You are doomed. The (relatively) recent DST changes were all implemented by manually changing code. Either you find a server you trust that gives you "local" time, or you subtract/add a manually entered offset.
for Europe fe. the DST starts on the last sunday 1:00 of march and ends on the last sunday of october.
You can calculate:
see this link Daylight Saving Time - Credits & feedback
European Economic Community:
Begin DST: Sunday March (31 - (5y/4 + 4) mod 7) at 1h U.T.
End DST: Sunday October (31 - (5y/4 + 1) mod 7) at 1h U.T.
Since 1996, valid through 2099
so I put this in a function that gives the adjusting seconds towards UTC for the European TZ, depending on the current date:
int adjustDstEurope()
{
// last sunday of march
int beginDSTDate= (31 - (5* year() /4 + 4) % 7);
Serial.println(beginDSTDate);
int beginDSTMonth=3;
//last sunday of october
int endDSTDate= (31 - (5 * year() /4 + 1) % 7);
Serial.println(endDSTDate);
int endDSTMonth=10;
// DST is valid as:
if (((month() > beginDSTMonth) && (month() < endDSTMonth))
|| ((month() == beginDSTMonth) && (day() >= beginDSTDate))
|| ((month() == endDSTMonth) && (day() <= endDSTDate)))
return 7200; // DST europe = utc +2 hour
else return 3600; // nonDST europe = utc +1 hour
}