Java Parse Date parseDate(String date)

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

Description

parse Date

License

Apache License

Declaration

public static Date parseDate(String date) throws ParseException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static Date parseDate(String date) throws ParseException {
        return getDateFormat().parse(date);
    }/*w  w  w  . j  a  v a  2s  .  co m*/

    public static Date parse(String date) throws ParseException {
        try {
            return parseTimestamp(date);
        } catch (ParseException e) {
            return parseDate(date);
        }
    }

    public static DateFormat getDateFormat() {
        return new SimpleDateFormat("yyyy-MM-dd");
    }

    public static Date parseTimestamp(String date) throws ParseException {
        return getTimetampFormat().parse(date);
    }

    public static DateFormat getTimetampFormat() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }
}

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, Locale locale)
  8. parseDate(String date, String expression)
  9. parseDate(String date, String format)