Java Parse Date parseDate(String date, String format)

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

Description

Parse a date on a given format.

License

Open Source License

Parameter

Parameter Description
date a parameter
format a parameter

Exception

Parameter Description
ParseException an exception

Declaration

public static Date parseDate(String date, String format)
        throws ParseException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Main {
    static Map<String, SimpleDateFormat> dateFormats = new HashMap<String, SimpleDateFormat>();

    /**/*  www. jav a2s.com*/
     * Parse a date on a given format. 
     * @param date
     * @param format
     * @return
     * @throws ParseException
     */
    public static Date parseDate(String date, String format)
            throws ParseException {
        if (!dateFormats.containsKey(format)) {
            dateFormats.put(format, new SimpleDateFormat(format));
        }

        return dateFormats.get(format).parse(date);
    }
}

Related

  1. parseDate(String date, Locale locale)
  2. parseDate(String date, String expression)
  3. parseDate(String date, String format)
  4. parseDate(String date, String format)
  5. parseDate(String date, String format)
  6. parseDate(String date, String format)
  7. parseDate(String date, String pattern)
  8. parseDate(String date, String pattern)
  9. parseDate(String date, String pattern)