中文日期转为数字类型日期 public static String timeConvert(String time) {String strTime = time.replaceAll("上午", "").replaceAll("下午", "");// 整点if (!strTime.contains("时")) {// 1~9时if (!strTime.contains("十")) {retu
public static String timeConvert(String time) { String strTime = time.replaceAll("上午", "").replaceAll("下午", ""); // 整点 if (!strTime.contains("时")) { // 1~9时 if (!strTime.contains("十")) { return "0" + ConvertCnNumberChar(strTime) + ":00"; } else if ("十".equals(strTime)) { return "10:00"; } else { // 11~19时 String tm = strTime.substring(1); return "1" + ConvertCnNumberChar(tm) + ":00"; } } else { String hour = ""; String min = ""; // 拆分“时”、“分” String s = strTime.replaceAll("时", " "); String[] ss = s.split("\\s+"); // 处理小时 // 1~9时 if (!ss[0].contains("十")) { hour = "0" + ConvertCnNumberChar(ss[0]); } else if ("十".equals(ss[0])) { hour = "10"; } else { // 11~19时 String tm = ss[0].substring(1); hour = "1" + ConvertCnNumberChar(tm); } // 处理分钟 if ("十".equals(ss[1].replace("分", ""))) { min = "10"; } else if (ss[1].replace("分", "").length() == 1) { // 一位数 min = "0" + ConvertCnNumberChar(ss[1]); } else if (ss[1].replace("分", "").length() == 3) { // 三位数 min = ConvertCnNumberChar(ss[1].replace("分", "").replaceAll("十", "")); } else { // 两位数 if ("二十".equals(ss[1].replace("分", "")) || "三十".equals(ss[1].replace("分", "")) || "四十".equals(ss[1].replace("分", "")) || "五十".equals(ss[1].replace("分", ""))) { min = ConvertCnNumberChar(ss[1].replace("分", "").replaceAll("十", "")) + "0"; } else { min = ConvertCnNumberChar(ss[1].replace("分", "").replaceAll("十", "1")); } } return hour + ":" + min; } } private static String ConvertCnNumberChar(String cnNumberStr) { String ALL_CN_NUMBER = "〇○零一二三四五六七八九"; String ALL_NUMBER = "000123456789"; StringBuffer buf = new StringBuffer(); for (int i = 0; i < cnNumberStr.length(); i++) { char c = cnNumberStr.charAt(i); int index = ALL_CN_NUMBER.indexOf(c); if (index != -1) { buf.append(ALL_NUMBER.charAt(index)); } else { buf.append(cnNumberStr.charAt(i)); } } return buf.toString(); }