getting local time over internet (NTP?)

Hello,

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).

Thanks in advance,
Jeroen

I am using worldtimeengine to get local time:
http://worldtimeengine.com

Hello Webmeister,

You have to request a key : is it free ?
Can you share your receiving/interpreting code for the .xml message ?

Thanks,
Jeroen

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.

Hi Jeroen,

But an NTP server always gives UTC time. And I need local time.

Wrote this some time ago Arduino Playground - DS1307OfTheLogshieldByMeansOfNTP and even if you don't have a RTC the library contains a DateTime class that does what you need.

Hopes this helps,

Hello Rob,

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...)

I need the code that does this checking for DST.

Any thoughts,
Jeroen

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.

[edit]stumbled upon this one http://home-4.tiscali.nl/~t876506/TZworld.html[/edit]

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!

What about if the DST changes

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.

What about if the DST changes ?
You are doomed

We need a sketch that can read the fingers(?) of an analog clock :slight_smile: FUN!

I've found my solution.

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 - (5
y/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
}

Isn't that nice ?

Best regards,
Jeroen

Very good searching Jeroen, Should be on the playground,

As info for the US is also on the site you might make your code more generic (so it can be added to Time lib or so)

instead int adjustDstEurope() ..

I think something like

enum TZONE = { US, EUR } ;

int adjustDST(TZONE TZ)
{
 ...
}

BTW can endDSTDate expressed as a function of beginDSTDate? formulas look quite alike?

Furthermore You don't take into account the hour the clock is set back. In Netherlands it is always between 2 and 3 I don't know for other countries.

Still well done!

your router might have a page with the time on it - mine does

Rob,

I set the time sync as an alarm every dag at 2:00, so normally it is synced with NTP (and automatically adjusted by the function above) at 2:00.

And indeed you can make this more generic, but I leave this for the expert.

Pantovich, my router doesn't, but still it can be a good solution.

Greetings,
Jeroen

Google must have a webservice that does this.