Here is my program time_play.c :
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int
main (void)
{
char *time_str = "2011-07-20 17:30:18";
time_t time_tm = getdate(time_str);
printf("str: %s and time: %s \n", time_str, ctime(&time_tm));
return 0;
}
And it’s output:
$ gcc -o time_play time_play.c
$ ./time_play
str: 2011-07-20 17:30:18 and time: Wed Dec 31 16:00:00 1969
It can be seen that time is getting value NULL. Why is it so?
Did you create a template file specifying the date format you are using?
From the man page:
Create a file like timetemplate.txt:
Then set the value of DATEMSK to point to it:
This code worked for me on OS X, in combination with setting the DATEMSK: