开发者

Changing the date format in C

My structure variable temp_var[0].tra开发者_StackOverflow社区de_date has the value of 20100614. I need to format this date like 6/14/2010. Could anybody please help me put the date in this format?


You could use sprintf, like this:

//date
int numeric_date = 20110430;

//convert integer to string
char numeric_date_string[9];
sprintf(numeric_date_string,"%d",numeric_date);

//format the string
char date[11];
sprintf(date,"%.4s/%.2s/%.2s",&numeric_date_string[0], &numeric_date_string[4], &numeric_date_string[6]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜