Program to Display the System Date and Time in C++ using Pointers

//This program will the system date and time for 5 seconds.
//Change the value given in loop, if you want to run it for more seconds time. 

#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<time.h>

void DateTime()
{
time_t theTime=time(NULL);
struct tm *aTime = localtime(&theTime);
int day=aTime->tm_mday;
int month=aTime->tm_mon+1;
int year=aTime->tm_year+1900;
int hour=aTime->tm_hour;
int mi=aTime->tm_min;
int sec=aTime->tm_sec;

clrscr();
cout<<"Today's Date is: "<<day<<"."<<month<<"."<<year<<endl;
cout<<"Current Time is: "<<hour<<":"<<mi<<":"<<sec<<endl;
}

void main()
{
for(int i=1;i<=5;i++)
{
DateTime();
delay(1000);
}
getch();
}



No comments

Post your comments

Powered by Blogger.