I'm trying to use the localtime() function to read the data provided by an NTP server.
When executing the following code (after receiving the current time via NTP):
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf("Current time is : %s\n", ctime(&rawtime));
int currentYear=timeinfo->tm_year;
printf("current year=%d\n",currentYear);
I get as output:
Current time is : Sat Dec 11 22:28:25 2010
current year=110
When using
strftime to print the content of the timeinfo data, I get 10 for the year. When replacing
localtime() in the code above with
gmtime(), the year is reported as 667.
So, what am I doing wrong? Is it that there is no time zone handling that localtime doesn't work, or is it something else?
Thanks,
hli
I'm trying to use the localtime() function to read the data provided by an NTP server.
When executing the following code (after receiving the current time via NTP):
So, what am I doing wrong? Is it that there is no time zone handling that localtime doesn't work, or is it something else?
Thanks,
hli