Java tutorial
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date string2Date(String s, String s1) { Date date = new Date(); try { String s2 = stringNull(s1); SimpleDateFormat simpledateformat = new SimpleDateFormat(s2); String s3 = stringNull(s); date = simpledateformat.parse(s3); } catch (Exception exception) { } return date; } public static String stringNull(String s) { if (s != null) { s = s.trim(); if (s.equals("") || s.equalsIgnoreCase("null")) s = ""; } return s; } }