Here you can find the source of parseDate(String datestr)
private static Date parseDate(String datestr)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { private static Date parseDate(String datestr) { if (null == datestr || "".equals(datestr)) { return null; }//from ww w . j a va 2s .c o m try { String fmtstr = null; if (datestr.contains(":") && datestr.contains("-")) { fmtstr = "yyyy-MM-dd HH:mm:ss"; } else if (datestr.contains(":") && datestr.contains("/")) { fmtstr = "yyyy/MM/dd HH:mm:ss"; } else if (datestr.contains("-")) { fmtstr = "yyyy-MM-dd"; } else if (datestr.contains("/")) { fmtstr = "yyyy/MM/dd"; } if (fmtstr != null) { SimpleDateFormat sdf = new SimpleDateFormat(fmtstr, Locale.UK); return sdf.parse(datestr); } else { return null; } } catch (Exception e) { return null; } } }