Go Down

Topic: Using GPS to update RTC and then re-adjust RTC for current timezone. (Read 957 times) previous topic - next topic

Okay... this is an odd one.

This is my current code...
Code: [Select]
 DateTime now = RTC.now();  
 yearVal = now.year();
 monthVal = now.month();
 dayVal = now.day();
 hourVal = now.hour();
 minuteVal = now.minute();
 secondVal = now.second();


My application starts with a somewhat accurate local time (Pacific time - non DST). The user has the option of hooking up a GPS. My program then gets the current time (UTC time) But... i need to subtract 8 hours from it and store that back on the RTC.

I set the GPS time in the RTC with this bit of code. It works pretty good...
Code: [Select]
   RTC.adjust(DateTime(GPS.year, GPS.month, GPS.day, GPS.hour, GPS.minute, GPS.seconds));


But... once the RTC has UTC time I need to somehow subtract 8 hours and update the RTC.

I think I need to use the unixtime function and subtract 8 * 3600 from the total number of seconds but I'm still lost... What do ya'll suggest?






Nevermind...

This is it:

Code: [Select]
RTC.adjust(DateTime(now.unixtime()-6*3600));

michinyon

You adjust the GPS time to your local time in your sketch,  BEFORE you try to put it into the RTC.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy