Java Parse Date Pattern YYYY parse(String date)

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

Description

parse

License

Apache License

Declaration

public static Date parse(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 parse(String date) throws ParseException {
        try {/*from www  .  ja  v  a 2s  . c  om*/
            return parseTimestamp(date);
        } catch (ParseException e) {
            return parseDate(date);
        }
    }

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

    public static Date parseDate(String date) throws ParseException {
        return getDateFormat().parse(date);
    }

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

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

Related

  1. parse(String date)
  2. parse(String date)
  3. parse(String date)
  4. parse(String date)
  5. parse(String date)
  6. parse(String date)
  7. parse(String date)
  8. parse(String date, String format)
  9. parse(String dateAsString)