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

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

Description

convert To Date

License

Open Source License

Parameter

Parameter Description
str a parameter
format a parameter

Exception

Parameter Description
ParseException an exception

Declaration

public static Date convertToDate(String str, String format) throws ParseException 

Method Source Code


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

import java.util.Date;

public class Main {
    public static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static Date convertToDate(String str) throws ParseException {
        return convertToDate(str, DEFAULT_FORMAT);
    }//  w w  w  . j a  v a2s.c o m

    public static Date convertToDate(String str, String format) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        return simpleDateFormat.parse(str);
    }
}

Related

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