Here you can find the source of getTimestamp(String str)
public static Timestamp getTimestamp(String str)
//package com.java2s; //License from project: Apache License import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseException; public class Main { public static Timestamp getTimestamp(String str) { try {/*from w ww . j a v a2 s . co m*/ if (str == null || str.equals("")) { return null; } if (str.length() == 10) { DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");// DateFormat.getDateInstance(DateFormat.MEDIUM, // java.util.Locale.CHINA); java.util.Date tempDate = df.parse(str); return new java.sql.Timestamp(tempDate.getTime()); } DateFormat df = DateFormat.getDateTimeInstance(); java.util.Date tempDate = df.parse(str); return new java.sql.Timestamp(tempDate.getTime()); } catch (ParseException ex) { return null; } } }