Creating a String of time & date, syntax advice needed.

I'm trying to load a string variable named timeStr with time "hh:mm:ss mm/dd/yyyy".
Sounds simple, but after the second element, it blows up on compile.

Here is the context:

String timeStr;  

if (RTC.read(tm)) {
   // Serial.print("Ok, Time = ");
    print2digits(tm.Hour);
    Serial.write(':');
    print2digits(tm.Minute);
    Serial.write(':');
    print2digits(tm.Second);
    Serial.print("  ");
    Serial.print(tm.Day);
    Serial.write('/');
    Serial.print(tm.Month);
    Serial.write('/');
    Serial.print(tmYearToCalendar(tm.Year));
    Serial.println();
   timeStr = tm.Hour + ":" + tm.Minute + ":" + tm.Second + "  " + tm.Month  + "/" + tm.Day + "/...");

With the 'timeStr = ' line terminated after tm.Minute, compile is fine. But any additional elements result in this error.

The error is:

invalid operands of types 'const char*' and 'const char [2]' to binary 'operator+'

Any advice greatly appreciated.

the right side of this:

timeStr = tm.Hour + ":" + tm.Minute + ":" + tm.Second + "  " + tm.Month  + "/" + tm.Day + "/...");

you cannot concatenate integers and string literals that way.

is timeStr a String?

timeStr = String(tm.Hour) + ":" + String(tm.Minute) ...

I assume timeStr is String. For the + to work, an instance of String object must exist on the left side. So you need

   timeStr = String(tm.Hour) + ":" + tm.Minute + ":" + tm.Second + "  " + tm.Month  + "/" + tm.Day + "/...");

this way a String is created and the + operator adds all other values to it.

btw: it is very ineffective and fragmenting memory

Thanks BullDogLowell!

I had tested the String (Var) syntax but I didn't have one on each element.
The example here didn't go that far, nor did my frozen brain.