Hi all,
why is the following code printing the wrong result?
/*
Returns the current time.
*/
char *time_stamp(){
char *str = (char *)malloc(sizeof(char) * 23);
int len;
struct timeval tv;
struct timezone tz;
struct tm *tm;
gettimeofday(&tv, &tz);
tm=localtime(&tv.tv_sec);
printf("\n\n\n%04d-%02d-%02d %d:%02d:%02d:%03d\n\n\n", tm->tm_year, tm->tm_mon,
tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec/1000);
sprintf(str, "%04d-%02d-%02d %d:%02d:%02d:%03d", tm->tm_year, tm->tm_mon,
tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec/1000);
return str;
}
it is printing the time right, but not the date.
it should be printing 2010-09-01 <time>...
but it is printing 0110-08-03