Here you can find the source of StrToDate(String Formate, String date)
public String StrToDate(String Formate, String date)
//package com.java2s; import java.text.*; import java.util.*; public class Main { public String StrToDate(String Formate, String date) { Calendar c = Calendar.getInstance(); try {/*w w w.j av a 2 s . c om*/ c.set(Calendar.YEAR, Integer.parseInt(date.substring(0, 4))); c.set(Calendar.MONTH, Integer.parseInt(date.substring(5, 7)) - 1); c.set(Calendar.DATE, Integer.parseInt(date.substring(8, 10))); java.util.Date d = c.getTime(); SimpleDateFormat f = new SimpleDateFormat(Formate); return f.format(d); } catch (Exception e) { System.err.println(e + date); return ""; } } public static String StrToDate(String date) { Calendar c = Calendar.getInstance(); try { c.set(Calendar.YEAR, Integer.parseInt(date.substring(0, 4))); c.set(Calendar.MONTH, Integer.parseInt(date.substring(5, 7)) - 1); c.set(Calendar.DATE, Integer.parseInt(date.substring(8, 10))); java.util.Date d = c.getTime(); SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd"); return f.format(d); } catch (Exception e) { System.err.println(e + date); return ""; } } public static Date strToDate(String str) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, Integer.parseInt(str.substring(0, 4))); c.set(Calendar.MONTH, Integer.parseInt(str.substring(5, 7)) - 1); c.set(Calendar.DATE, Integer.parseInt(str.substring(8, 10))); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c.getTime(); } public String getTime() { java.sql.Time ent = new java.sql.Time(System.currentTimeMillis()); return ent.toString(); } }