C Program To Display Digital Clock
Learn How To Display Digital Clock in C Programming Language. This digital clock will display the current time with real time updates of time.
This C Program makes use of a System Library File which has its header as time.h. The time.h header file defines Two Macro, Four Variable Types and various other functions for manipulating time and date.
Must Read: System Shutdown C Program For Linux Ubuntu
C Program To Display Digital Clock (Live Clock)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <stdio.h> #include <time.h> int main() { time_t ts, flag = 1; struct tm *ct; printf("\n\n\n\tActive Digital Clock\n\t"); while(1) { ts = time(NULL); ct = localtime(&ts); if(flag || ct -> tm_min % 59 == 0) { if(!flag) printf("\b\b\b\b\b\b"); printf("%02d:%02d:%02d", ct -> tm_hour, ct -> tm_min, ct -> tm_sec); flag = 0; printf("\b\b"); continue; } if(ct -> tm_sec % 59 == 0) { printf("\b\b\b"); printf("%02d:", ct -> tm_min); } printf("%02d", ct ->tm_sec); printf("\b\b"); } return 0; } |
Must Read: C Program To Print System Date and Time
Output

If you have any compilation error or doubts in this C Program To Display Active Digital Clock, let us know about it in the Comment Section below.
Thanks. This program code for printing live clock works perfectly fine. Can we actually make a program to display only static time?
Yes. There are so many built in methods in C Libraries to display static time and date. You will get it on google.
Sir how i get contact no.
Sir could you give me link please.
Can u please explain This:
flag || ct