Here you can find the source of stringToDate(String strDate)
public static Date stringToDate(String strDate) throws ParseException
//package com.java2s; //License from project: Open Source License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { private static final String PATTERN = "yyyyMMdd"; public static final String PATTERN_TIME4 = "yyyyMMddHHmm"; public static Date stringToDate(String strDate) throws ParseException { DateFormat df = new SimpleDateFormat(PATTERN); Date date = df.parse(strDate); return date; }// w w w . j a v a2s .c o m public static Date stringToDate(String strDate, String pattern) throws ParseException { DateFormat df = new SimpleDateFormat(pattern); Date date = df.parse(strDate); return date; } public static Calendar StringtoDate(String sb) throws ParseException { DateFormat df = new SimpleDateFormat(PATTERN_TIME4); Date date = df.parse(sb); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(date.getTime()); return cal; } }