Java Parse Date parseDate(String date, String pattern)

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

Description

Methods Descrip:

License

LGPL

Parameter

Parameter Description
date a parameter
pattern a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static Date parseDate(String date, String pattern) throws Exception 

Method Source Code

//package com.java2s;
/**//from   w w w .ja  v a  2s. c o  m
 *
 * Methods Descrip:Converts a line of text into an array of lower case words
 * using a BreakIterator.wordInstance().
 * <p>
 *
 * This method is under the Jive Open Source Software License and was
 * written by Mark Imbriaco.
 *
 * @param text
 *            a String of text to convert into an array of words
 * @return text broken up into an array of words.
 *
 */

import java.util.Date;

public class Main {
    /**
     *
     * Methods Descrip:
     *
     * @param date
     * @param pattern
     * @return
     * @throws Exception
     *
     */
    public static Date parseDate(String date, String pattern) throws Exception {
        Date returnDate = null;
        if (pattern == null || pattern.equals("") || pattern.equals("null")) {
            pattern = "yyyy-MM-dd";
        }
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(pattern);
        try {
            returnDate = sdf.parse(date);
        } catch (Exception e) {
            throw e;
        }
        return returnDate;
    }
}

Related

  1. parseDate(String date, String format)
  2. parseDate(String date, String format)
  3. parseDate(String date, String format)
  4. parseDate(String date, String pattern)
  5. parseDate(String date, String pattern)
  6. parseDate(String date, String pattern, TimeZone zone)
  7. parseDate(String dateAsString)
  8. parseDate(String dateAsString)
  9. parseDate(String dateFormat, String value)