Here you can find the source of getTimesByStr(String dataStr)
public static Timestamp getTimesByStr(String dataStr)
//package com.java2s; //License from project: Open Source License import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Timestamp getTimesByStr(String dataStr) { Date d = getDate(dataStr); String newTime = getString2(d); return Timestamp.valueOf(newTime); }//from ww w. ja v a2 s. c o m public static Date getDate(String str) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = dateFormat.parse(str); } catch (ParseException e) { e.printStackTrace(); } return date; } public static String getDate(int num) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, -num + 1); Date date = new Date(cal.getTimeInMillis()); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String str = df.format(date); return str; } public static String getString2(Date date) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String newStr = dateFormat.format(date); return newStr; } }