Here you can find the source of stringToTime(String format, String sDate)
public static Date stringToTime(String format, String sDate) throws Exception
//package com.java2s; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date stringToTime(String format, String sDate) throws Exception { DateFormat df = new SimpleDateFormat(format); Date _date = df.parse(sDate); if (timeToString(format, _date).equals(sDate)) { return _date; } else {/*from w w w. j a va 2 s . c o m*/ throw new Exception(sDate + " is error"); } } public static String timeToString(String format, Date date) { DateFormat df = new SimpleDateFormat(format); return df.format(date); } }