Home > Article > Backend Development > C program to print digital clock with current time
In this section, we will learn how to make a digital clock using C language. To handle time we can use the time.h header file. This header file has some function signatures for handling date and time related issues.
The four important components of time.h are as follows
size_t This size_t is basically an unsigned integer type. This is the result of sizeof().
clock_t Used to store processor time
time_t This is used to store calendar Time
struct tm This is a structure. It helps to save the entire date and time.
#include <stdio.h> #include <time.h> int main() { time_t s, val = 1; struct tm* curr_time; s = time(NULL); //This will store the time in seconds curr_time = localtime(&s); //get the current time using localtime() function //Display in HH:mm:ss format printf("%02d:%02d:%02d", curr_time->tm_hour, curr_time->tm_min, curr_time->tm_sec); }
23:35:44
The above is the detailed content of C program to print digital clock with current time. For more information, please follow other related articles on the PHP Chinese website!