Pages: [1]   Go Down
Author Topic: Using GPS to update RTC and then re-adjust RTC for current timezone.  (Read 752 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay... this is an odd one.

This is my current code...
Code:
 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:
   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?




Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does it have to be done within the same routine?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nevermind...

This is it:

Code:
RTC.adjust(DateTime(now.unixtime()-6*3600));
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3077
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: