Here you can find the source of getSqlTimestampFromShortDate(String date)
public static Timestamp getSqlTimestampFromShortDate(String date)
//package com.java2s; //License from project: Apache License import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Timestamp getSqlTimestampFromShortDate(String date) { Date _date = getShortDate(date); int _year = Integer.parseInt(getYear(_date)); int _month = Integer.parseInt(getMonth(_date)) - 1; int _day = Integer.parseInt(getDay(_date)); Calendar _cal = Calendar.getInstance(); Timestamp _value = new Timestamp(_cal.getTimeInMillis()); try {/*from w w w . ja v a 2 s . c o m*/ _cal.set(_year, _month, _day); _value = new Timestamp(_cal.getTimeInMillis()); } catch (Exception e) { } return _value; } public static String getShortDate() { String _value = getShortDate(new Date()); return _value; } public static String getShortDate(Date date) { if (date == null) date = new Date(); SimpleDateFormat _sdf = new SimpleDateFormat("MM/dd/yyyy"); String _value = _sdf.format(date); return _value; } public static Date getShortDate(String date) { SimpleDateFormat _sdf = new SimpleDateFormat("MM/dd/yyyy"); Date _value = new Timestamp(Calendar.getInstance().getTimeInMillis()); try { _value = new Date(_sdf.parse(date).getTime()); } catch (Exception e) { } return _value; } public static String getYear(Date date) { SimpleDateFormat _sdf = new SimpleDateFormat("yyyy"); String _value = _sdf.format(date); return _value; } public static String getMonth(Date date) { SimpleDateFormat _sdf = new SimpleDateFormat("MM"); String _value = _sdf.format(date); return _value; } public static String getDay(Date date) { SimpleDateFormat _sdf = new SimpleDateFormat("dd"); String _value = _sdf.format(date); return _value; } public static String getTime(Date date) { SimpleDateFormat _sdf = new SimpleDateFormat("hh:mm aa"); String _value = _sdf.format(date); return _value; } }