Java Parse Date parseDate(String dateStr, String dateFormat)

Here you can find the source of parseDate(String dateStr, String dateFormat)

Description

Parse the date in string format based on date format and return a Date object

License

Apache License

Parameter

Parameter Description
dateStr Example 2012-12-15:10:10:10
dateFormat Example yyyy-MM-dd HH:mm:ss

Exception

Parameter Description
ParseException an exception

Declaration

public static Date parseDate(String dateStr, String dateFormat) throws ParseException 

Method Source Code


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

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    /**/*from   w  w  w .  j  a  v a  2s .  co m*/
     * Parse date based on date format yyyy/MM/dd-HH:mm:ss
     * @param dateStr
     * @return
     * @throws ParseException
     */
    public static Date parseDate(String dateStr) throws ParseException {
        return parseDate(dateStr, "yyyy/MM/dd-HH:mm:ss");
    }

    /**
     * Parse the date in string format based on date format and return a Date object
     * @param dateStr Example 2012-12-15:10:10:10
     * @param dateFormat Example yyyy-MM-dd HH:mm:ss
     * @return
     * @throws ParseException
     */
    public static Date parseDate(String dateStr, String dateFormat) throws ParseException {
        DateFormat format = new SimpleDateFormat(dateFormat);
        return format.parse(dateStr);
    }
}

Related

  1. parseDate(String dateStr)
  2. parseDate(String dateStr)
  3. parseDate(String datestr)
  4. parseDate(String dateStr)
  5. parseDate(String dateStr, SimpleDateFormat... formats)
  6. parseDate(String dateStr, String dateFormat)
  7. parseDate(String dateStr, String format)
  8. parseDate(String dateStr, String format)
  9. parseDate(String dateStr, String... formats)