Java Parse Date parseDate(String dateValue, String strFormat)

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

Description

parse Date

License

LGPL

Declaration

public static Date parseDate(String dateValue, String strFormat) 

Method Source Code

//package com.java2s;
/**//from   w  ww . j av  a2 s .  c o  m
 * Core-level framework class: String and Date basic utility methods.
 * <br><br>
 * Encapsulates utility methods for everyday programming tasks
 * with Strings, Dates and other common stuff.
 * <br>
 * Creation date: 18/09/2003<br>
 * Last Update: 18/09/2003<br>
 * (c) 2003 Martin Cordova<br>
 * This code is released under the LGPL license<br>
 * @author Martin Cordova (some code written by Carlos Pineda)
 */

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

import java.util.Date;

public class Main {

    public static Date parseDate(String dateValue, String strFormat) {

        if (dateValue == null)
            return null;

        if (strFormat == null)
            strFormat = "yyyy-MM-dd";

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

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

        return newDate;
    }
}

Related

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