how to memorize date and time

Hi all. i use arduino mega with real time clock module DS3231 to manage some air condition system. I would like to know how to memorize time and date in a string. I need this to memorize for example, time and date of the last alarm. for example,

with this comand : Serial.print(clock.dateFormat("l, d F Y, H:i:s", dt)); i get: Sunday, 16 October 2016, 21:59:58

but with this comand: String mystring; mystring = clock.dateFormat("l, d F Y, H:i:s", dt) Serial.print(mystring); why i get?? unknown, 00 unknown 0000, 00:00:00

What is wrong? Someone can help me? (excuse for my bad english)

for example,

I'm sure that the fine folks at could help you with your snippets. Here, we're so dumb we need to see all of your code AND links to non-standard libraries that you are using.

While this is painful to make guesses because you only provided a snippet - you can go and check for yourself in the library code what's happening and why it fails...

would you be actually using Korneliusz Jarzebski's DS3231 Real-Time Clock library ?

They I would say that is because This is a buggy library - go see the function

char* DS3231::dateFormat(const char* dateFormat, RTCDateTime dt)
    char buffer[255];
    return buffer;

It allocates a huge buffer on the stack, tries to fill it in with the right info (I would argue also it has a bug if you put a space or any non formatter at the end of the format String because then the buffer won't be null terminated) and return the buffer... but the buffer being on the stack, it's already invalid and up for grab by any new function call... you are lucky the Serial.print works because nothing else messes up the stack in between so the bits are still there but when you try to instantiate a String class object and read the buffer plenty happens behind your back and the stack is all messed up.

“how to memorize date and time”

In one of the Goon Show scripts Eccles got a man to write it down on a piece of paper. :slight_smile: