
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C program to print digital clock with current time
In this section we will see how to make a digital clock using C. To work with time we can use the time.h header file. This header file has some function signatures that are used to handle date and time related issues.
The four important components of time.h is like below
size_t This size_t is basically the unsigned integral type. This is the result of sizeof().
clock_t This is used to store the processor time
time_t This is used to store calendar time
struct tm This is a structure. It helps to hold the entire date and time.
Example Code
#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); }
Output
23:35:44
- Related Articles
- C++ Program to print current Day, Date and Time
- How to create digital clock with textview in android?
- 8085 Program to simulate a real-time clock
- How to get current time zone in android using clock API class?
- Real Time Clock (RTC) with Arduino
- Convert time from 24 hour clock to 12 hour clock format in C++
- How to print current date and time using Python?
- Program to simulate a real-time clock in 8085 Microprocessor
- Python to create a digital clock using Tkinter
- C++ Program to find maximum possible smallest time gap between two pair of clock readings
- Java Program to Get Current Date/Time
- How to print current date and time in a JSP page?
- Java Program to display Current Time in another Time Zone
- Python program to find difference between current time and given time
- Java Program to Display current Date and Time

Advertisements