Java Date Parse getDateFromString(String date, String pattern)

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

Description

get Date From String

License

Apache License

Declaration

public static Date getDateFromString(String date, String pattern) throws ParseException 

Method Source Code

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

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

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

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

    public static Date getDateFromString(String date, String pattern) throws ParseException {
        SimpleDateFormat sDateFormat = getDateFormat(pattern);

        synchronized (sDateFormat) {
            return sDateFormat.parse(date);
        }// w ww.  j  av a  2  s  . com
    }

    public static SimpleDateFormat getDateFormat(String pattern) {
        SimpleDateFormat sDateFormat = (SimpleDateFormat) formats.get(pattern);
        if (sDateFormat == null) {
            sDateFormat = new SimpleDateFormat(pattern);
            formats.put(pattern, sDateFormat);
        }
        return sDateFormat;
    }
}

Related

  1. getDateFromString(final String dateString, final String dateFormatString)
  2. getDateFromString(final String inputStringDate, final String format)
  3. getDateFromString(String _date, String _format)
  4. getDateFromString(String date)
  5. getDateFromString(String date, String fmt)
  6. getDatefromString(String dateStr)
  7. getDateFromString(String dateStr, String datePattern)
  8. getDateFromString(String dateString)
  9. getDateFromString(String dateString)