Chronodot Setting Date Time

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 Setting Date Time

Post by ilovetofu »

Using the Chronodot, I am explicitly setting the date time but when I then display the date and time, the time is correct, but it gives me the wrong date.

The output of DisplayDateTime() is: 21 Sep 2005 16:00:00

Is there something I am doing wrong?

#include "RTClib.h"
RTC_DS1307 RTC;
...
void setup()
{
RTC.begin();
char *myDate = "September 5 2015";
char *myTime = "16:00:00";
RTCSetDateTime(myDate, myTime);
DisplayDateTime();
}

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

void DateTimeToSerial()
{
DateTime now = RTC.now();
String str = "";
str += String(now.day());
str += String(" ");
str += String(GetMonthName(now.month()));
str += String(" ");
str += String(now.year());
str += String(" ");
if (now.hour() < 10)
str += String("0");
str += String(now.hour());
str += String(":");
if (now.minute() < 10)
str += String("0");
str += String(now.minute());
str += String(":");
if (now.second() < 10)
str += String("0");
str += String(now.second());
Serial.println(str);
}

const char* GetMonthName(int month)
{
static char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
return months[month-1];
}

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

Re: Chronodot Setting Date Time

Post by ilovetofu »

If I change the date format to "Sep 5 2015", which seems to be the format of __DATE__
the date is then displayed as "34 Sep 2002"!!!

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

Re: Chronodot Setting Date Time

Post by ilovetofu »

SOLVED!
I had to use the following format "Sep 05 2015", which now gives me the correct date :)

char *myDate = "Sep 05 2015";
char *myTime = "16:00:00";

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

Return to “Clock Kits (discontinued)”