Here you can find the source of StringToDate(String s)
public static Date StringToDate(String s)
//package com.java2s; //License from project: Open Source License import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public final static String PATTERN_YMDHMS = "yyyy-MM-dd HH:mm:ss"; public static Date StringToDate(String s) { Date date = new Date(); try {//w ww . j a v a 2 s.com SimpleDateFormat simpledateformat = new SimpleDateFormat(PATTERN_YMDHMS); ParsePosition parseposition = new ParsePosition(0); date = simpledateformat.parse(s, parseposition); } catch (Exception ex) { } return date; } public static Date StringToDate(String s, String reg) { Date date = new Date(); try { SimpleDateFormat simpledateformat = new SimpleDateFormat(reg); ParsePosition parseposition = new ParsePosition(0); date = simpledateformat.parse(s, parseposition); } catch (Exception ex) { } return date; } }