/**
* Convertit une chaine (String) en date.
*
* @link http://java.sun.com/j2se/1.4/docs/api/java/text/SimpleDateFormat.html
* @link http://developer.java.sun.com/developer/qow/archive/120/
*
* @since JDK 1.1
*/

import java.util.Date;
import java.text.SimpleDateFormat;

public class TestDate
{
	public static void testParseDate(String sDate) {
		try {
			Date d = stringToDate(sDate, "yyyy-MM-dd");
			System.out.println(d.toString());
		} catch(Exception e) {
			System.err.println("Exception :");
			e.printStackTrace();
		}
	}

	public static Date stringToDate(String sDate, String sFormat) throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
		return sdf.parse(sDate);
	}

	public static void main(String[] args) {
		testParseDate("2001-10-20");
		testParseDate("2002/10-20"); // ParseException
		testParseDate(null);     // NullPointerException
	}

}