Here you can find the source of getTimestamp(String time, String pattern)
public static Timestamp getTimestamp(String time, String pattern)
//package com.java2s; //License from project: Open Source License import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; public class Main { public static Timestamp getTimestamp(String time) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); format.setLenient(false);/*from www . j a v a 2s. c o m*/ Timestamp ts = null; try { ts = new Timestamp(format.parse(time).getTime()); } catch (ParseException e) { e.printStackTrace(); } return ts; } public static Timestamp getTimestamp(String time, String pattern) { DateFormat format = new SimpleDateFormat(pattern); format.setLenient(false); Timestamp ts = null; try { ts = new Timestamp(format.parse(time).getTime()); } catch (ParseException e) { e.printStackTrace(); } return ts; } }