Apr 6, 2017 at 3:45am UTC
I used time.h to get system time. The time it returned is 21.20.00 7 FEB 1997.
My question is: Can any one explain why it is returning this time?
Thanks
Apr 6, 2017 at 3:58am UTC
Best is to show us your program. And the obvious question is what does your system clock say elsewhere?
Apr 6, 2017 at 4:39am UTC
#include<iostream>
#include<ctime>
#include<time.h>
using namespace std;
int main()
{
time_t timer;
tm *ti , *gtm;
double second;
ti=localtime(&timer);
gtm=gmtime(&timer);
if(timer!=-1)
cout<<"tm structure value"<<endl;
cout<<"Hour "<<ti->tm_hour;
cout<<endl<<"Minute"<<ti->tm_min;
cout<<endl<<"Second "<<ti->tm_sec<<endl;
cout<<"Time is "<<asctime(ti)<<endl;
cout<<"GTM time is "<<asctime(gtm)<<endl;
return 0;
}
I can't understand "What does your system clock say elsewhere?".
Apr 6, 2017 at 4:55am UTC
Well, if the time in a Window is the same then your system clock needs a reset or the battery is flat. :)
Apr 6, 2017 at 5:15am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include<iostream>
#include<time.h>
using namespace std;
int main()
{
time_t timer;
tm *ti , *gtm;
time(&timer); // *** <-- !!! THIS SOLVES IT !!! ***
ti = localtime(&timer);
gtm = gmtime(&timer);
cout << "tm structure value:" << endl;
cout << " Hour\t" << ti->tm_hour << endl;
cout << " Minute\t" << ti->tm_min << endl;
cout << " Second\t" << ti->tm_sec << endl;
cout << " Time is\t" << asctime(ti) << endl;
cout << "GMT time is\t" << asctime(gtm) << endl;
return 0;
}
Late fix pointer-enhancement.
Last edited on Apr 6, 2017 at 6:19am UTC
Apr 6, 2017 at 5:21am UTC
Do i have to reset the system clock from bios?
Apr 6, 2017 at 5:59am UTC
I reset the system clock from cmd and BIOS. I reset the time. Still same error.
Any other ideas?
Apr 6, 2017 at 6:09am UTC
Did you fix your program?
Look carefully at @kemort's post.
Apr 6, 2017 at 6:16am UTC
Overwhelmed with excitement at solving the problem, never to be heard from again, or maybe the battery was flat and blew up the motherboard changing it.
I hope it was the former and not the latter. :)