Time Conversion - RTC

I’m using the Adafruit Chronodot with RTClib.h (RTC_DS1307)

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.

Have you looked at the now() function in DateTime?

http://playground.arduino.cc/Code/DateTime

Hi, Also, perhaps Adafruit can assist since I assume the library has been provided by them ?

  • dan

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

b4ip:
unsigned long offset = 36000;

Australia, right?

That was quick. Yes, Sydney time. Up late hacking Arduino.