Here you can find the source of parseDateTime(String date)
Parameter | Description |
---|---|
date | the date |
Parameter | Description |
---|---|
ParseException | the parse exception |
public static Date parseDateTime(String date) throws ParseException
//package com.java2s; //License from project: Open Source License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Main { /** The Constant UTC_TIME_ZONE. */ public final static TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC"); /** The Constant DATE_TIME_PATTERN. */ public final static String DATE_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'"; /**/* w ww. ja v a 2s . c o m*/ * Description goes here. * * @param date the date * @return the date * @throws ParseException the parse exception */ public static Date parseDateTime(String date) throws ParseException { if (date == null) { throw new NullPointerException("Provided date is null"); } Date parsedDate = null; DateFormat dateFormat = new SimpleDateFormat(DATE_TIME_PATTERN, Locale.ENGLISH); dateFormat.setTimeZone(UTC_TIME_ZONE); try { parsedDate = dateFormat.parse(date); // if (!sdf.getTimeZone().hasSameRules(DateUtils.UTC_TIME_ZONE)) { // throw new Exception("The given date <" + date + "> is not in UTC time zone "); // } } catch (ParseException e) { throw new ParseException("Impossible to parse the given string <" + date + "> into UTC date ", e.getErrorOffset()); } return parsedDate; } }