我正在尝试编写一个program in C
,从表单中的键盘读取数据,dd-mm-yy
并希望将日期显示为January 3rd, 1999
. 我该怎么做?
试试吧,希望能帮助解决你的问题
#include <stdio.h>
#include <time.h>
int main()
{
struct tm tm_info;
char buffer[255];
char days[32][5] = {" ","1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st"};
strptime("09-07-2017", "%d-%m-%Y ", &tm_info);
strftime(buffer, 26, "%B", &tm_info);
printf("%s ",buffer);
strftime(buffer, 26, "%d", &tm_info);
int day = int(buffer[0]-'0')*10 + int(buffer[1]-'0');
printf("%s, ",days[day]);
strftime(buffer, 26, "%Y", &tm_info);
printf("%s ",buffer);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句