Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Timezone & DST Setting

Status
Not open for further replies.

nayakajit87

Member level 5
Joined
Aug 13, 2018
Messages
84
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
1,065
Dear all

i am looking for sample code for timezone adjustment of time and day light savihttps://ww1.microchip.com/downloads/en/devicedoc/20005010f.pdf
above ic used for RTC date and time

i am using PIC18F24k40 series for RTC time read and write,

I am looking for simple c code where i could adjust time based on timezone.

Is there any algorithm available for such application.

Arduino has library for such application. Is there any sample c code available PIC micro controller.
 

Hi,

In many applications the RTC contains local time, thus no time zone needed.

For any application with internet access (IoT) I recommend to use UTC (GMT) in the RTC.
Time zone correction is just addding the offset to UTC. (You really need no code example for this)

DST is more difficult, because it depends on countries and if it is enabled at all.
Usually you need to know at which date (may not be a fixed date) at which DST starts and at which it ends.
If your current local time is within this limits, just add the offset.

Klaus
 

I'm working on a rather complicated project that relies on some parts working in UTC and some in local time, incorporating DST. To make it worse, it has to calculate daily sunrise and sunset times and find the time zone as well - based only on latitude and longitude! It uses an ESP32 processor so giving you code won't help but the general principle I use is this:

1. keep the RTC running in UTC (= GMT) all the time
2. keep a software clock running in parallel to the RTC and periodically set it to the RTC to keep them in sync.
3. calculate a seconds value based on (Hours * 3600)+(Minutes * 60)+Seconds. Expand this to days, months and years as necessary.
3. Add to the seconds value (TZ hour difference * 3600).
4. Add to that (DST hours difference * 3600).
5. Convert the final value back to the time again to get the adjusted TZ + DST time. If using date as well, add that to the calculation.

It isn't as difficult as it seems and it will cater for different DST shifts and both full hour and half hour time zone differences.

In my application I have to cater for some events being triggered by UTC and some by DST so I recalculate as above every second and keep two time structures updated, using whichever is appropriate for the particular event. You can automatically calculate DST start and end dates if you can find the rules for your country. In the UK it is the last Sunday in March and the the last Sunday in October, both at 01:00 UTC.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top