Java 中日期格式转换 /** * 字符串转换为java.util.Date
* 支持格式为 yyyy.MM.dd G 'at' hh:mm:ss z 如 '2002-1-1 AD at 22:10:59 PSD'
* yy/MM/dd HH:mm:ss 如 '2002/1/1 17:55:00'
* yy/MM/dd HH:mm:ss pm 如 '2002/1/1 17:55:00 pm'
* yy-MM-dd HH:mm:ss 如 '2002-1-1 17:55:00'
* yy-MM-dd HH:mm:ss am 如 '2002-1-1 17:55:00 am'
* @param time String 字符串
* @return Date 日期
*/ public static Date stringToDate(String time){ SimpleDateFormat formatter; int tempPos=time.indexOf("AD") ; time=time.trim() ; formatter = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss z"); if(tempPos>-1){ time=time.substring(0,tempPos)+ "公元"+time.substring(tempPos+"AD".length());//china formatter = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss z"); } tempPos=time.indexOf("-"); if(tempPos>-1&&(time.indexOf(" ")<0)){ formatter = new SimpleDateFormat ("yyyyMMddHHmmssZ"); } else if((time.indexOf("/")>-1) &&(time.indexOf(" ")>-1)){ formatter = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss"); } else if((time.indexOf("-")>-1) &&(time.indexOf(" ")>-1)){ formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"); } else if((time.indexOf("/")>-1) &&(time.indexOf("am")>-1) ||(time.indexOf("pm")>-1)){ formatter = new SimpleDateFormat ("yyyy-MM-dd KK:mm:ss a"); } else if((time.indexOf("-")>-1) &&(time.indexOf("am")>-1) ||(time.indexOf("pm")>-1)){ formatter = new SimpleDateFormat ("yyyy-MM-dd KK:mm:ss a"); } ParsePosition pos = new ParsePosition(0); java.util.Date ctime = formatter.parse(time, pos); return ctime; } /** * 将 java.util.Date 格式转换为字符串格式'yyyy-MM-dd HH:mm:ss'(24 小时制)
* 如 Sat May 11 17:24:21 CST 2002 to '2002-05-11 17:24:21'
* @param time Date 日期
* @return String 字符串
*/ public static String dateToString(Date time){ SimpleDateFormat formatter; form...