Chronodot - Epoch to DateTime

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ilovetofu
 
Posts: 35
Joined: Sat Aug 22, 2015 1:38 am

Chronodot - Epoch to DateTime

Post by ilovetofu »

I'm using the Adafruit Chronodot with RTClib.h
My code connects to a time server which gives me the current UNIX time (number of seconds since 1/1/1970 UTC) as an unsigned long.

How do I convert this value into human readable date and time values so I can set the date/time?

My function to set the date time:
void RTCSetDateTime(char *theDate, char *theTime)
{
RTC.adjust(DateTime(theDate, theTime));
}

Example:
char myDate[] = "Sep 05 2015";
char myTime[] = "14:37:30";
RTCSetDateTime(my_date, my_time);

Also, if I include <Time.h> then I get a stack of compile errors that seem to conflict with RTCLib.

User avatar
ilovetofu
 
Posts: 35
Joined: Sat Aug 22, 2015 1:38 am

Re: Chronodot - Epoch to DateTime

Post by ilovetofu »

SOLVED:

Thanks for the responses but it was simple once I worked out how the "adjust" method and the DateTime object works. It seems DateTime has at least one override.

I just had to create the DateTime object by passing in the epoch rather than passing in 2 variables as char arrays that represent the date/time in human readable format.

void RTCSetDateTime(char *theDate, char *theTime)
{
rtc.adjust(DateTime(theDate, theTime));
}

unsigned long offset = 36000;

void RTCSetDateTimeFromEpoch(unsigned long t)
{
t += offset;
rtc.adjust(DateTime(t));
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Clock Kits (discontinued)”