I have this function (which works fine):
String Esper::rtcTimeString() {
DateTime now = rtc.now();
char buf[] = "MM/DD/YY hh:mm:ss";
return now.toString(buf);
}
I'd like to have a default value of "MM/DD/YY hh:mm:ss" but also pass an argument to a parameter such as "MM/DD/YYYY" if I want to override this default behavior.
Typically, in the definitions .h file I would do something like:
String rtcTimeString(char ts[] = "MM/DD/YY hh:mm:ss");
and subsequently in the .cpp:
String Esper::rtcTimeString(char ts[]) {
DateTime now = rtc.now();
return now.toString(ts);
}
However that results in the same returned time string every time.
e.g.
1/6/2020 12:01:12
1/6/2020 12:01:12
1/6/2020 12:01:12
How can I implement a parameter such that the functionality is the same as in the first code block?