讲一个日期根据给定的字符串输出相应的格式

程序代码:

string Date::toString(string format_flag)  const {
    int length = format_flag.size();
    char *a = new char[81];
    if(length == 7) {sprintf(a, "%s/%s/%s", month, day, year);}
    if(length == 11) {sprintf(a, "%02s/%02s/%04s", month, day, year);}
    if(length == 13) {
        switch(month) {
        case 1 : sprintf(a, "January %02s,%04s", day, year); break;
        case 2 : sprintf(a, "Febrary %02s,%04s", day, year); break;
        case 3 : sprintf(a, "March %02s,%04s", day, year); break;
        case 4 : sprintf(a, "April %02s,%04s", day, year); break;
        case 5 : sprintf(a, "May %02s,%04s", day, year); break;
        case 6 : sprintf(a, "June %02s,%04s", day, year); break;
        case 7 : sprintf(a, "July %02s,%04s", day, year); break;
        case 8 : sprintf(a, "Augest %02s,%04s", day, year); break;
        case 9 : sprintf(a, "September %02s,%04s", day, year); break;
        case 10 : sprintf(a, "October %02s,%04s", day, year); break;
        case 11 : sprintf(a, "November %02s,%04s", day, year); break;
        case 12 : sprintf(a, "December %02s,%04s", day, year); break;
        }
    }
    return string(a);
}

你可能感兴趣的:(讲一个日期根据给定的字符串输出相应的格式)