Java Parse Date parseDateTime(String date)

Here you can find the source of parseDateTime(String date)

Description

Description goes here.

License

Open Source License

Parameter

Parameter Description
date the date

Exception

Parameter Description
ParseException the parse exception

Return

the date

Declaration

public static Date parseDateTime(String date) throws ParseException 

Method Source Code


//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;
    }
}

Related

  1. parseDateTime(@Nullable String s)
  2. parseDateTime(final String dateTime)
  3. parseDateTime(String _date)
  4. parseDateTime(String currDate, String format)
  5. parseDateTime(String d, String t)
  6. parseDateTime(String date, String format, String locale, String timeZone)
  7. parseDateTime(String date, String time)
  8. parseDateTime(String dateTime)
  9. parseDateTime(String dateTimeStr)