Here you can find the source of getTimestamp(String dateString, String format)
public static Timestamp getTimestamp(String dateString, String format) throws Exception
//package com.java2s; /*//from w w w . jav a2s .c o m * This software is distributed under the terms of the FSF * Gnu Lesser General Public License (see lgpl.txt). * * This program is distributed WITHOUT ANY WARRANTY. See the * GNU General Public License for more details. */ import java.sql.Timestamp; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static Timestamp getTimestamp(String dateString, String format) throws Exception { Date date = getDate(dateString, format); if (date == null) return null; return new Timestamp(date.getTime()); } public static Date getDate(String dateString, String format, TimeZone tz) throws Exception { if (dateString == null || format == null || dateString.equals("") || tz == null) return null; SimpleDateFormat formatter = new SimpleDateFormat(format); formatter.setTimeZone(tz); ParsePosition pos = new ParsePosition(0); return formatter.parse(dateString, pos); } public static Date getDate(String dateString, String format) throws Exception { return getDate(dateString, format, TimeZone.getDefault()); } }