Java Parse Date parseDate(String dateValue)

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

Description

Parse a string and return a date value

License

Apache License

Parameter

Parameter Description
dateValue a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static Date parseDate(String dateValue) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String C_TIME_PATTON_DEFAULT = "yyyy-MM-dd HH:mm:ss";
    public static final String C_DATE_PATTON_DEFAULT = "yyyy-MM-dd";

    /**/* w w  w .j a va 2 s . com*/
     * Parse a string and return a date value
     *
     * @param dateValue
     * @return
     * @throws Exception
     */
    public static Date parseDate(String dateValue) {
        return parseDate(C_DATE_PATTON_DEFAULT, dateValue);
    }

    /**
     * Parse a string and return the date value in the specified format
     *
     * @param strFormat
     * @param dateValue
     * @return
     * @throws ParseException
     * @throws Exception
     */
    public static Date parseDate(String strFormat, String dateValue) {
        if (dateValue == null)
            return null;

        if (strFormat == null)
            strFormat = C_TIME_PATTON_DEFAULT;

        SimpleDateFormat dateFormat = new SimpleDateFormat(strFormat);
        Date newDate = null;

        try {
            newDate = dateFormat.parse(dateValue);
        } catch (Exception pe) {
            newDate = null;
        }

        return newDate;
    }
}

Related

  1. parseDate(String dateString, String pattern)
  2. parseDate(String dateText)
  3. parseDate(String datetime)
  4. parseDate(String dateVal)
  5. parseDate(String dateValue)
  6. parseDate(String dateValue, String strFormat)
  7. parseDate(String dttm)
  8. parseDate(String dttm)
  9. parseDate(String format, String value)