Java Parse Date parseDate(String date)

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

Description

parse Date

License

Open Source License

Declaration

public static Date parseDate(String date) throws ParseException 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    private static String DATE_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ssZ";
    private static String DATE_FORMAT_STRING_WITHOUT_TZ = "yyyy-MM-dd'T'HH:mm:ss";

    public static String parseDate(final Date date) throws ParseException {
        return new SimpleDateFormat(DATE_FORMAT_STRING).format(date);
    }//from   ww w .  j ava  2s  .  co  m

    public static Date parseDate(String date) throws ParseException {
        if (date.endsWith("Z")) {
            date = date.substring(0, date.length() - 1);
        }
        if (date.length() == 10) {
            date = date + "T00:00:00";
        }
        date = date.replaceAll("^(\\d{4})(\\d{2})(\\d{2})T(\\d{2})(\\d{2})(\\d{2})$", "$1-$2-$3T$4:$5:$6");
        date = date.replaceAll("^(\\d{4})(\\d{2})(\\d{2})$", "$1-$2-$3T00:00:00");
        return new SimpleDateFormat(DATE_FORMAT_STRING_WITHOUT_TZ).parse(date);
    }
}

Related

  1. parseDate(String date)
  2. parseDate(String date)
  3. parseDate(String date)
  4. parseDate(String date)
  5. parseDate(String date)
  6. parseDate(String date)
  7. parseDate(String date)
  8. parseDate(String date)
  9. parseDate(String date)