Here you can find the source of string2Timestamp(String strDateTime, String pattern)
public static Timestamp string2Timestamp(String strDateTime, String pattern)
//package com.java2s; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String PATTERN_STANDARD = "yyyy-MM-dd HH:mm:ss"; public static Timestamp string2Timestamp(String strDateTime, String pattern) { if (strDateTime == null || strDateTime.equals("")) { throw new java.lang.IllegalArgumentException("Date Time Null Illegal"); }// w w w.ja va 2 s.co m if (pattern == null || pattern.equals("")) { pattern = PATTERN_STANDARD; } SimpleDateFormat sdf = new SimpleDateFormat(pattern); Date date = null; try { date = sdf.parse(strDateTime); } catch (ParseException e) { throw new RuntimeException(e); } return new Timestamp(date.getTime()); } }