Here you can find the source of toTime(String format, String str)
public static Timestamp toTime(String format, String str)
//package com.java2s; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static SimpleDateFormat sdf = new SimpleDateFormat(); public static Timestamp toTime(String format, String str) { Date date = toDate(format, str); Timestamp timestamp = new Timestamp(date.getTime()); return timestamp; }/*from ww w . ja v a2 s .co m*/ public static Date toDate(String format, String str) { Date date = null; if (format == null) { sdf.applyPattern("yyyy-MM-dd HH:mm:ss"); } else { sdf.applyPattern(format); } try { date = sdf.parse(str); } catch (ParseException e) { e.printStackTrace(); } return date; } }