Here you can find the source of getTime(String dateStr, String formate)
public static long getTime(String dateStr, String formate)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss"; public static long getTime(String dateStr, String formate) { Date date;/*w w w.ja v a2s .c o m*/ try { date = getDate(dateStr, formate); return date.getTime(); } catch (ParseException e) { return -1; } } public static long getTime(String dateStr) { return getTime(dateStr, DEFAULT_FORMAT); } public static String getDate(Date date, String formate) { SimpleDateFormat sf = new SimpleDateFormat(formate); return sf.format(date); } public static Date getDate(String dateStr, String formate) throws ParseException { SimpleDateFormat sf = new SimpleDateFormat(formate); return sf.parse(dateStr); } }