Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static final Pattern DATE_PATTERN = Pattern.compile("(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)"); public static Date parseDate(String dateString) { Matcher m = DATE_PATTERN.matcher(dateString.trim()); if (!m.matches()) { throw new IllegalArgumentException("\"" + dateString + "\" must be in YYYY-MM-DD format."); } Calendar c = Calendar.getInstance(); c.set(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)) - 1, Integer.parseInt(m.group(3))); return c.getTime(); } }