Linux datetime/locale library in C
I need a tiny standalone library in C on linux platform that will return "Friday" when provided with (2009, 11, 13) for example. I would like it to be locale aware, meaning, returning day and month names in language set开发者_开发百科 by the user.
Any suggestions?
You can tie together mktime and strftime to do that:
char daybuf[20];
struct tm time_str;
time_str.tm_year = YEAR - 1900;
time_str.tm_mon = MONTH - 1;
time_str.tm_mday = DAY;
time_str.tm_hour = 0;
time_str.tm_min = 0;
time_str.tm_sec = 1;
time_str.tm_isdst = -1;
if (mktime(&time_str) != -1)
strftime(daybuf, sizeof(daybuf), "%A", &time_str);
精彩评论