Here you can find the source of getTime(String dateStr, String format)
public static long getTime(String dateStr, String format)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static long getTime(String dateStr, String format) { long time = -1; Date date = getDate(dateStr, format); if (date != null) { time = getDate(dateStr, format).getTime(); }//w ww .j a v a 2 s. c o m return time; } public static long getTime(String dateStr) { long time = -1; String format = "yyyy-MM-dd HH:mm:ss"; Date date = getDate(dateStr, format); if (date != null) { time = getDate(dateStr, format).getTime(); } return time; } public static Date getDate(String dateStr, String formatString) { Date date = null; try { SimpleDateFormat sdf = new SimpleDateFormat(formatString); date = sdf.parse(dateStr); } catch (Exception e) { e.printStackTrace(); } return date; } public static Date getDate(String dateStr) { return getDate(dateStr, "yyyy-MM-dd HH:mm:ss"); } }