time format printing

How to print a particular time in HH:MM format where HH means no. of hours and MM means no. of minutes?
For eg.:
if the time is 3 a.m.
then it should be printed as 03:00.


1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <ctime>

int main()
{
    constexpr size_t buf_size = 128;
    std::tm time_point {};
    time_point.tm_hour = 3;
    char buf[buf_size];
    strftime(buf, buf_size, "%H:%M", &time_point);
    std::cout << buf;
}
03:00
Last edited on
Topic archived. No new replies allowed.