Here you can find the source of toTimestamp(String str, String format)
public static Timestamp toTimestamp(String str, String format)
//package com.java2s; import java.sql.Timestamp; import java.text.*; import java.util.TimeZone; public class Main { public static Timestamp toTimestamp(String str) { if (str == null) { return null; }/*from w w w . ja v a 2s .co m*/ try { return Timestamp.valueOf(str.trim()); } catch (IllegalArgumentException iae) { return null; } } public static Timestamp toTimestamp(String str, String format) { if (str == null) { return null; } try { return new Timestamp(parseDate(str, format).getTime()); } catch (Exception e) { return null; } } public static java.util.Date parseDate(String value, String pattern) { try { TimeZone tz = TimeZone.getDefault(); String dateFormat = pattern; SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); sdf.setTimeZone(tz); // Parse date java.util.Date parsed = null; parsed = sdf.parse(value); return parsed; } catch (ParseException e) { return null; } } }