I have an Arduino Uno project which is recording student attendance using fingerprint sensor. So when sensor found a match, the serial monitor will be printing out Student ID and current time like this:
DateTime now;
void setup()
{
...
}
void loop()
{
.....
//found a match
Serial.print("Found ID #");
Serial.println(finger.fingerID);
Serial.print("Time->");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
}
Sample result will be:
Found ID#1
Time-> 18:11:54
I would like to store the time into a variable and print it out instead of printing hour, minute, and second separately. How can I do that???
I have tried to do like this as below but I'm getting an error, I would like to store it as a string. How can I do that?
string time = now.hour() + ':' + now.minute() + ':' + now.second();
time_tis a better choice. It is defined as seconds since midnight Jan 1 1970 (aka unix time). For more details see github.com/PaulStoffregen/Time/blob/master/TimeLib.h#L21