import java.util.HashMap;
import java.util.Map;
public class MyTest {
private static final Map months = new HashMap();
static {
months.put("一月","01");
months.put("二月","02");
months.put("三月","03");
months.put("四月","04");
months.put("五月","05");
months.put("六月","06");
months.put("七月","07");
months.put("八月","08");
months.put("九月","09");
months.put("十月","10");
months.put("十一月","11");
months.put("十二月","12");
}
public static String dateTrans(String date){
if(date==null){
return null;
}
String[] dates = date.split("-");
if(dates.length != 3 || months.get(dates[1])==null){
throw new RuntimeException("格式错误");
}
return dates[2]+"-"+months.get(dates[1])+"-"+(dates[0].length()==1?("0"+dates[0]):dates[0]);
}
public static void main(String[] args){
System.out.println(MyTest.dateTrans("6-五月-2018"));
System.out.println(MyTest.dateTrans("23-五月-2018"));
}
}
温馨提示:答案为网友推荐,仅供参考