Local time with NTP #11150
Replies: 2 comments 1 reply
-
Hi, Now that's interesting, I just posted my adapted version of ntptime.py for my own needs with timezone and DST adjustment here: I'm nowhere near your programming level and it's makeshift quick and dirty. But I'll surely be looking into your solution. |
Beta Was this translation helpful? Give feedback.
-
I have implemented a much heavier weight solution in the past, in C not python, but the same approach would apply. I use the Google geocode API to translate e.g. a street address to latitude and longitude, and then the TZ API to get the timezone, UTC offset and DST correction. It is even possible (although unreliable) to use the geolocation API to detect the device's location based on visible wifi routers and cell masts. The API is HTTPS and the responses are in JSON. The APIs are free for (pretty generous) limited usage, although you do need a Google developer account and a credit card. Just make sure your code doesn't go into some infinite loop and rack up a massive bill ! I generally check once a day, just after 2AM to catch any DST changes. Time of day comes from NTP, as usual. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Greetings to all.
Like others, I ran into the problem of setting local time via the ntptime module.
I think setting the RTC time to UTC is the correct way, then when it comes to using/viewing it you will need to do some work.
So I wrote a module that allows you to transform RTC time into the local time zone, also managing daylight saving time (DST).
The idea is visible here: localPTZtime
I decided to provide the result as a string in ISO 8601 format, this allows to keep the information on the "distance" from UTC (zone designator).
It will always be possible to decompose the string if the individual parts are needed.
It's a work in progress, may change in the future.
I hope it's helpful.
Edit:
To improve compatibility, in addition to the ISO string, there is now a function that also returns a tuple in the time_struct like format.
Beta Was this translation helpful? Give feedback.
All reactions