#include<stdio.h>
#include<graphics.h>
#include<time.h>
int gd=DETECT,gm,x,y;
void main()
{
time_t now;
struct tm *timeinfo;
initgraph(&gd,&gm,"..\\BGI\\");
x=getmaxx()/2-80;
y=getmaxy()/2-20;
while(!kbhit())
{
time(&now);
timeinfo=localtime(&now);
printf("%2d : %2d : %2d",timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec);
delay(1000);
cleardevice();
}
getch();
}
Search This Blog
Showing posts with label system time. Show all posts
Showing posts with label system time. Show all posts
Digital Clock C Program
This is a c program to display a digital clock showing correct time. It reads time at 1 second interval and displays it on the screen. To know how to get date and time in C, see this post: How to Get Time and Date in C - C Program to Read and Display Time and Date
How to Get Time and Date in C - C Program to Read and Display Time and Date
In this post, we will discuss how to read system time (current time) and date in c. To get system time and date, we use the time.h header file. It contains functions related to time and date. The function time() reads the current time and stores in the variable given as parameter. For example, if we call time(now), then the variable now is assigned the current date and time value. This parameter should be of type time_t. A sample code is:
time_t now; time ( &now );
Note that we should pass the reference to a variable of type time_t. But, the value stored by the function time() contains all information including date and time. So, the value appears to be an unintelligible random number. There fore, to extract hours, minutes, seconds, year, month, day of month etc from this value, we should convert into an object of structure struct tm. The function localtime() converts the value for us. This conversion to date and time can be done as follows:
C Program to Display Analog Clock Showing Correct Time - Computer Graphics Program
This is a c program which reads the current time from system and shows an analog clock that shows correct time. The clock hand ticks and the three hands (hour hand, minute hand, second hand) are used to to show correct time. This real-time analog clock c program uses graphics.h library to display the clock and time.h library to get current time. The program output is as follows:
Subscribe to:
Posts (Atom)