Here you can find the source of string2Long(String sourceTime, String dataFormat)
public static long string2Long(String sourceTime, String dataFormat)
//package com.java2s; //License from project: Open Source License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static long string2Long(String sourceTime, String dataFormat) { long longTime = 0L; DateFormat f = new SimpleDateFormat(dataFormat); Date d = null;/*from www. j av a 2 s. co m*/ try { d = f.parse(sourceTime); } catch (ParseException e) { e.printStackTrace(); } longTime = d.getTime(); return longTime; } public static Date parse(String strDate, String pattern) throws ParseException { try { return getFormatter(pattern).parse(strDate); } catch (ParseException pe) { throw new ParseException("Method parse in Class DateUtil err: parse strDate fail.", pe.getErrorOffset()); } } private static SimpleDateFormat getFormatter(String parttern) { return new SimpleDateFormat(parttern); } }