Java tutorial
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static Date stringToDate(String str) { Date date = null; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); try { date = formatter.parse(str); return date; } catch (Exception e) { return null; } } public static Date stringToDate(String str, String format) { Date date = null; SimpleDateFormat formatter = new SimpleDateFormat(format); try { date = formatter.parse(str); return date; } catch (Exception e) { return null; } } public static Date stringToDate(String str, String format, Locale locale) { Date date = null; SimpleDateFormat formatter = new SimpleDateFormat(format, locale); try { date = formatter.parse(str); return date; } catch (Exception e) { return null; } } }