time.h

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
closed account (48T7M4Gy)
Best is to show us your program. And the obvious question is what does your system clock say elsewhere?
#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?".
closed account (48T7M4Gy)
Well, if the time in a Window is the same then your system clock needs a reset or the battery is flat. :)
closed account (48T7M4Gy)
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
Do i have to reset the system clock from bios?
I reset the system clock from cmd and BIOS. I reset the time. Still same error.
Any other ideas?
Did you fix your program?

Look carefully at @kemort's post.
closed account (48T7M4Gy)
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. :)
Thanks everyone.
Topic archived. No new replies allowed.