Java Parse Date parseDate(String date)

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

Description

parse date with the default pattern

License

Open Source License

Parameter

Parameter Description
date string date

Return

the parsed date

Declaration

public static Date parseDate(String date) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**//  w  w  w  .j  a va 2s .  c o  m
     * default date format pattern
     */
    public final static String DATE_FORMAT = "yyyy-MM-dd";

    /**
     * parse date with the default pattern
     *
     * @param date string date
     * @return the parsed date
     */
    public static Date parseDate(String date) {
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        try {
            return format.parse(date);
        } catch (ParseException e) {
            return new Date();
        }
    }

    public static Date parseDate(String date, String pattern) {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        try {
            return format.parse(date);
        } catch (ParseException e) {
            return new 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)