public static void main(String[] args) throws IOException {
testConvertZwrq();
}
private static void testConvertZwrq() {
String[] list = new String[] { "二○○九年四月三十日", "○九年四月三十日", "二○○九年十二月三十一日", "二零零九年十二月三十一日" };
for (String s : list) {
Date d = convertCnDate(s);
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(d));
}
}
public static Date convertCnDate(String cprq) {
int yearPos = cprq.indexOf("年");
int monthPos = cprq.indexOf("月");
String cnYear = cprq.substring(0, yearPos);
String cnMonth = cprq.substring(yearPos + 1, monthPos);
String cnDay = cprq.substring(monthPos + 1, cprq.length() - 1);
String year = ConvertCnYear(cnYear);
String month = ConvertCnDateNumber(cnMonth);
String day = ConvertCnDateNumber(cnDay);
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, Integer.parseInt(year));
c.set(Calendar.MONTH, Integer.parseInt(month)-1);
c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day));
return c.getTime();
}