Code example for SimpleDateFormat

Methods: parse, setTimeZone

0
		} catch (IndexOutOfBoundsException e) {
			throw new JsonParseException("Invalid length");
		} 
 
		// Parse the well-formatted date string 
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd'T'HH:mm:ss'.'SSSZ"); 
		dateFormat.setTimeZone(TimeZone.getDefault());
		Date date = dateFormat.parse(s);
 
		return date;
	} 
 
	/** 
	 * Serializes a Date object to an ISO-8601 formatted date string 
	 */ 
	public static String serialize(Date date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd'T'HH:mm:ss'.'SSS'Z'", Locale.getDefault());
		dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));