Here you can find the source of parseString2Long(String strDate)
public static Long parseString2Long(String strDate)
//package com.java2s; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static String FORMAT_STR_TIME = "yyyy-MM-dd HH:mm:ss"; public static DateFormat FORMAT_TIME = new SimpleDateFormat(FORMAT_STR_TIME); private static SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static TimeZone timeZone = TimeZone.getTimeZone(TimeZone.getDefault().getID()); public static Long parseString2Long(String strDate) { return new Long(parseDate(strDate, FORMAT_STR_TIME).getTime()); }/*from ww w . j a va2 s.co m*/ public static Date parseDate(String strDate, String format) { try { if (strDate == null || strDate.equals("")) return null; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); return simpleDateFormat.parse(strDate); } catch (Exception e) { } return new Date(); } public static Date parseDate(String strDate, String format, boolean seccessFlag) { try { if (strDate == null || strDate.equals("")) return null; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); return simpleDateFormat.parse(strDate); } catch (Exception e) { try { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); return simpleDateFormat.parse(strDate); } catch (Exception ex) { try { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); return simpleDateFormat.parse(strDate); } catch (Exception ee) { } } } return null; } public static String parse(Date date) { String str = ""; try { FORMAT_TIME.setTimeZone(timeZone); TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); str = FORMAT_TIME.format(date); } catch (Exception ee) { ee.printStackTrace(); } return str; } public static Date format(String time) throws ParseException { if (time == null) { return null; } sf.setTimeZone(timeZone); TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); return sf.parse(time); } }