Here you can find the source of getTimestampFromString(String dateStr)
public static java.sql.Timestamp getTimestampFromString(String dateStr)
//package com.java2s; //License from project: Open Source License import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static java.sql.Timestamp getTimestampFromString(String dateStr) { if (dateStr == null || dateStr.equals("")) { return null; }/*from w w w.ja v a 2 s.c o m*/ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); ParsePosition pos = new ParsePosition(0); Date strtodate = formatter.parse(dateStr, pos); if (strtodate == null) { strtodate = new Date(); } return new java.sql.Timestamp(strtodate.getTime()); } public static String getTime() { Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString = formatter.format(currentTime); String min; min = dateString.substring(14, 16); return min; } }