Skip to main content

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 imI'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();

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, second separately. How can I do that???

I have tried to do like this as below but im getting error, I would like to store it as a string. How can I do that?

string time = now.hour() + ':' + now.minute() + ':' + now.second();

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();
Question Protected by VE7JRO
Source Link
Michael
  • 33
  • 1
  • 3

How to combine time into a variable

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, second separately. How can I do that???

I have tried to do like this as below but im getting error, I would like to store it as a string. How can I do that?

string time = now.hour() + ':' + now.minute() + ':' + now.second();