Translate

Code to Get Current time and time left for next day(12 format) Program

#include<iostream>
#include<conio.h>
#include<ctime>
using namespace std;
class time
{
public:
void showtime(time &);
    void diff(time &,time &);
int sec;
int min;
int hr;
}C,D;

void time::showtime(time &t)
{
cout<<"CURRENT TIME OF THE SYSTEM\n\n";
cout<<"Second    "<<t.sec<<endl;
cout<<"Minutes   "<<t.min<<endl;
cout<<"Hours     "<<t.hr<<"\n\n"<<endl;
}
void time::diff(time &t,time &r)
{
cout<<"TIME LEFT FOR THE NEXT DAY\n\n";
int a,b,c,d,min=0,f=0;
a=t.sec+t.min*60+t.hr*3600;
b=r.sec+r.min*60+r.hr*3600;
c=b-a;
for(int a=0;c>=60;a++)
{
c=c-60;
min++;
}
for(int a=0;min>=60;a++)
{
min=min-60;
f++;
}

cout<<"SECONDS      "<<c;
cout<<"\nMINUTES    "<<min;
cout<<"\nHOURS      "<<f;

}
int main()
{
    time_t t = time(0);   // get time now
    struct tm * now = localtime( & t );
   /* cout << (now->tm_year + 1900) << '-'
         << (now->tm_mon + 1) << '-'
         <<  now->tm_mday
         << endl;
cout << now->tm_min;
cout << now->tm_hour;*/
cout<<"\t\tWELCOME";
cout<<"\t\tCURRENT TIME AND TIME LEFT FOR NEXT DAY";
C.sec=now->tm_sec;
C.min=now->tm_min;
C.hr=now->tm_hour;
C.showtime(C);
D.hr=24;
D.min=00;
D.sec=00;
C.diff(C,D);
getche();
}

Previous
Next Post »

Contact Form

Name

Email *

Message *