Hi, all
I am newbie to arduino. I need your help to solve my problem. Well, I want to display date and time on serial monitor by using RTC and arduino due. But the problem is the format of date and time. I have tried to display date and time using this code. But this code give me an output like yyyy/m/d h:m:s. I need to edit the format like yyyy/mm/dd hh:mm:ss.
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;
void setup () {
Serial.begin(9600);
#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
rtc.begin();
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop () {
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print("0");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print("0");
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
}
I need your help and suggestions. Thanks in advance.
Regards,
Intan