Java String to Date toDate(String sdate, SimpleDateFormat dateFormater)

Here you can find the source of toDate(String sdate, SimpleDateFormat dateFormater)

Description

to Date

License

Open Source License

Declaration

public static Date toDate(String sdate, SimpleDateFormat dateFormater) 

Method Source Code

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

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

import java.util.Date;

public class Main {
    private final static ThreadLocal<SimpleDateFormat> DATE_FORMATER = new ThreadLocal<SimpleDateFormat>() {
        @Override//from  ww w.j a  v  a2  s  . c om
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
    };

    public static Date toDate(String sdate) {
        return toDate(sdate, DATE_FORMATER.get());
    }

    public static Date toDate(String sdate, SimpleDateFormat dateFormater) {
        try {
            return dateFormater.parse(sdate);
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. toDate(String pattern, String date)
  2. toDate(String pString, String pFormat)
  3. toDate(String s)
  4. toDate(String s)
  5. toDate(String s, String format)
  6. toDate(String sDate, String sFmt)
  7. toDate(String str)
  8. toDate(String str)
  9. toDate(String str)