Code example for SimpleDateFormat

Methods: parse

0
 
	private static final String ISO_FORMAT = "yyyy-MM-dd";
	private static final String ISO_FORMAT_LONG = "yyyy-MM-dd'T'HH:mm:ssZ";
 
	public static Calendar parseIsoDate(String strDate) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat(ISO_FORMAT);
		Date date = sdf.parse(strDate);
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal;
	} 
	 
	public static Calendar parseIsoDateTime(String strDate) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat(ISO_FORMAT_LONG);
		Date date = sdf.parse(strDate);
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal;
	}