How can i print only time in C++?

You should use time method with localtime() and strftime() function for formatting time:-

#include <stdio.h>
#include <time.h>

int main() {
    time_t t = time(NULL);
    struct tm *tm = localtime(&t);
    char time_str[9]; // buffer to hold formatted time string
    strftime(time_str, sizeof(time_str), "%H:%M:%S", tm); // format time string
    printf("Current time: %s\n", time_str);
    return 0;


Added  Feb 17, 12:18 am

Article tags

SignUp with Email