把不同格式的字符串转为日期类型的工具 import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;public class DateConverter {static SimpleDateFormat [] sdfs = new SimpleDateFormat[] {new SimpleD
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateConverter { static SimpleDateFormat [] sdfs = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM-dd"), new SimpleDateFormat("yyyy/MM/dd"), new SimpleDateFormat("MM-dd-yyyy"), new SimpleDateFormat("MM/dd/yyyy") }; public static Date getDate(String dateString) { for (int i = 0; i < sdfs.length; i++) { try { return sdfs[i].parse(dateString); } catch (ParseException e) { continue; } } return null; } }