
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- C++ Program to print current Day, Date and Time
- How to create digital clock with textview in android?
- Real Time Clock (RTC) with Arduino
- Python to create a digital clock using Tkinter
- 8085 Program to simulate a real-time clock
- How to get current time zone in android using clock API class?
- 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
- Java Program to Get Current Date/Time
- Count how many times the given digital clock shows identical digits in C++
- Java Program to display Current Time in another Time Zone
- Print a number containing K digits with digital root D in C++
- How to print current date and time in a JSP page?
- C++ Program to find maximum possible smallest time gap between two pair of clock readings
Advertisements