Here you can find the source of stringToTimestamp()
public static Timestamp stringToTimestamp()
//package com.java2s; //License from project: Apache License import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Timestamp stringToTimestamp() { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = df.format(new Date()); return Timestamp.valueOf(time); }//from ww w.j av a 2 s .c o m public static Timestamp stringToTimestamp(String dateStr) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); Calendar cal = Calendar.getInstance(); try { Date date = sdf.parse(dateStr); date.getTime(); cal.setTime(date); return new Timestamp(cal.getTimeInMillis()); } catch (ParseException e) { e.printStackTrace(); } cal.setTime(new Date()); return new Timestamp(cal.getTimeInMillis()); } public static Timestamp stringToTimestamp(String dateStr, String pattern) { Timestamp dateTime = new Timestamp(System.currentTimeMillis()); String date = dateStr + " 00:00:00"; try { dateTime = Timestamp.valueOf(date); } catch (Exception e) { e.printStackTrace(); } return dateTime; } public static Timestamp stringToTimestamp(String dateStr, String HHmmss, String pattern) { Timestamp dateTime = new Timestamp(System.currentTimeMillis()); String date = dateStr + " " + HHmmss; try { dateTime = Timestamp.valueOf(date); } catch (Exception e) { e.printStackTrace(); } return dateTime; } }