Home > Backend Development > C++ > C program to print digital clock with current time

C program to print digital clock with current time

PHPz
Release: 2023-09-23 16:57:04
forward
845 people have browsed it

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.

Sample 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);
}
Copy after login

Output

23:35:44
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template