Java Parse Date parseDate(String strFormat, String dateValue)

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

Description

Parse a string and return the date value in the specified format

License

Apache License

Parameter

Parameter Description
strFormat a parameter
dateValue a parameter

Exception

Parameter Description
ParseException an exception
Exception an exception

Declaration

public static Date parseDate(String strFormat, String dateValue) 

Method Source Code

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

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

import java.util.Date;

public class Main {
    /**/*from  w  w  w  . j ava2 s.com*/
     * 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 = "yyyy-MM-dd HH:mm:ss";
        }

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

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

        return newDate;
    }
}

Related

  1. parseDate(String strDate)
  2. parseDate(String strDate)
  3. parseDate(String strDate)
  4. parseDate(String strDate)
  5. parseDate(String strDate, String format)
  6. parseDate(String string)
  7. ParseDate(String string, String format)
  8. parseDate(String t)
  9. parseDate(String text)