Java Date from String convertToDate(String strDate, String format)

Here you can find the source of convertToDate(String strDate, String format)

Description

convert To Date

License

Open Source License

Declaration

public static Date convertToDate(String strDate, String format) 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static Date convertToDate(String strDate, String format) {

        if (strDate == null || format == null) {
            return null;
        }//  w  ww . j  a  va2 s .  co m

        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try {
            date = sdf.parse(strDate.trim());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}

Related

  1. convertToDate(String ddMMyy)
  2. convertToDate(String inDate)
  3. convertToDate(String input)
  4. convertToDate(String str)
  5. convertToDate(String str, String format)
  6. convertToDate(String strDate, String format)
  7. convertToDate(String val)
  8. convertToDate(String value)
  9. convertToDateTimeNoSec(String date)