Black Lives Matter - Action and Equality. ... Adafruit joins the Stop Hate for Profit campaign.
0

Chronodot - Epoch to DateTime
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Chronodot - Epoch to DateTime

by ilovetofu on Wed Sep 16, 2015 9:35 am

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.

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

Re: Chronodot - Epoch to DateTime

by ilovetofu on Wed Sep 16, 2015 11:25 am

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));
}

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

Please be positive and constructive with your questions and comments.