Here you can find the source of StringToDate1(String strDate)
public static Date StringToDate1(String strDate) throws ParseException
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date StringToDate1(String strDate) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = sdf.parse(strDate); return new java.util.Date(date.getTime()); }/*from www . ja va2 s . co m*/ public static Date getTime() { try { return getDate("yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) { e.printStackTrace(); } return null; } public static Date getDate() { try { return getDate("yyyy-MM-dd"); } catch (ParseException e) { e.printStackTrace(); } return null; } public static Date getDate(String format) throws ParseException { SimpleDateFormat df = new SimpleDateFormat(format); Date date = new Date(System.currentTimeMillis()); return convertStringToDate(df.format(date), format); } public static Date convertStringToDate(String time, String format) throws ParseException { if (format == null) { format = "yyyy-MM-dd"; } SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.parse(time); } }