Java tutorial
//package com.java2s; //License from project: Apache License import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** * String->Timestamp * * @param str * @return */ public static Timestamp strToTimestamp(String str) { return Timestamp.valueOf(str); } /** * String->imestamp * * @param str * @param format * @return */ public static Timestamp strToTimestamp(String str, String format) { // "yyyy-MM-dd HH:mm:ss" SimpleDateFormat df1 = new SimpleDateFormat(format); Date date1 = new Date(); try { date1 = df1.parse(str); } catch (ParseException e) { e.printStackTrace(); } String time = df1.format(date1); // Timestamp ts = Timestamp.valueOf(time); return Timestamp.valueOf(time); } }