Java Date Parse convertStringToDate(String dateString, String pattern)

Here you can find the source of convertStringToDate(String dateString, String pattern)

Description

convert String To Date

License

Open Source License

Declaration

public static Date convertStringToDate(String dateString, String pattern) 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_DATE_FORMAT = "yyyy-MM-dd";

    public static Date convertStringToDate(String dateString, String pattern) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.parse(dateString);
    }//from   www  .ja  v a2 s .c o m

    public static Date convertStringToDate(String dateString) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
            return sdf.parse(dateString);
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. convertStringToDate(String dateInput, String formatter)
  2. convertStringToDate(String dateStr, String format)
  3. convertStringToDate(String dateStr, String pattern)
  4. convertStringToDate(String dateString, String dateFormat)
  5. convertStringToDate(String dateString, String dateFormat)
  6. convertStringToDate(String dateText)
  7. convertStringToDate(String dateTime)
  8. convertStringToDate(String dateTime)
  9. convertStringToDate(String dt)