我的结构变量 temp_var[0].trade_date
的值为 20100614
。我需要将此日期格式化为 6/14/2010
。有人可以帮我把日期改成这种格式吗?
最佳答案
您可以使用 sprintf,如下所示:
//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]);
关于更改C中的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5839366/