1507. 转变日期格式
class Solution {
public:
string reformatDate(string date) {
int day,month=0,year;
char month_str[10];
sscanf(date.c_str(),"%d%*s %s %d",&day,month_str,&year);
string month_name[]={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
for(int i=0;i<12;i++){
if(month_name[i]==month_str){
month=i+1;
break;
}
}
char res[20];
sprintf(res,"%04d-%02d-%02d",year,month,day);
return res;
}
};
网友评论