I want to get the current date (day, mon and year). I found out there are some functions in C to do that like ctime (get the string of time), localtime and gmtime. I tried with following code but the output are different. I get this output:
The date and time is Tue Apr 20 2010 (which is correct)
The year is : 110
The year is : 110.
Does anybody know why?
int main(int argc, char** argv)
{
time_t now;
if((now = time(NULL)) == (time_t)-1)
{
puts("Failure in getting time");
}
else {
printf("The date and time is: %s\n", ctime(&now));
printf("The year is: %ld\n", localtime(&now)->tm_year);
printf("The year is: %ld\n", gmtime(&now)->tm_year);
}
getchar();
}