I am new to c and trying out on strptime
function, which converts string time to structure tm
. After converting i am not getting right time. everything is fine but year is displaying wrong(default year 1900).
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
int main()
{
struct tm tm;
char *pszTemp = "Mon Apr 25 09:53:00 IST 2016";
char szTempBuffer[256];
memset(&tm, 0, sizeof(struct tm));
memset(szTempBuffer, 0, sizeof(szTempBuffer));
strptime(pszTemp, "%a %b %d %H:%M:%S %Z %Y", &tm);
strftime(szTempBuffer, sizeof(szTempBuffer), "%Y-%m-%d %H:%M:%S", &tm);
printf("Last Boot Time after parsed = %s\n", szTempBuffer);
return 0;
}
Output : 1900-04-25 09:53:00