Format hour and minute integers to HH:MM format (char*)
You don't want a char *, you want a character array, i.e. you have to
allocate the memory for the string, not only for a pointer. That being
said, you can build the string one character at a time like this:



char timestr[6];
timestr[0] = '0' + _hour / 10;
timestr[1] = '0' + _hour % 10;
timestr[2] = ':';
timestr[3] = '0' + _minute / 10;
timestr[4] = '0' + _minute % 10;
timestr[5] = '\0';


Then you can use timestr just as you would use a char*.

Edit 1: If you are not too short on RAM, you could allocate the string
statically, and have the C runtime initialize the characters ':' and
'\0' at program startup. Then you just have to set the four remaining
chars on each conversion:

static char timestr[] = "--:--";  // initialized only once, with template
timestr[0] = '0' + _hour / 10;
timestr[1] = '0' + _hour % 10;
timestr[3] = '0' + _minute / 10;
timestr[4] = '0' + _minute % 10;


Edit 2: Maybe the “simplest”, in the sense “closest to what you had
in mind”, would be to use a String object:

String timestr = String() + (_hour &lt; 10 ? "0" : "") + _hour
    + ':' + (_minute &lt; 10 ? "0" : "") + _minute;


You could print() that String directly, or retrieve the internal
char* with the c_str() method.

I added this method only for completeness. Although simple in the source
code, it would not be my first choice: it uses more memory, it is more
CPU-intensive and – what worries me most – it uses heap allocation,
which carries the risk of memory fragmentation.