Java String to Date toDate(String dateStr, String format)

Here you can find the source of toDate(String dateStr, String format)

Description

to Date

License

Open Source License

Declaration

public static Date toDate(String dateStr, 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 Date toDate(String dateStr, String format) throws ParseException {
        return getSimpleDateFormat(format).parse(dateStr);
    }// w w w  .j  a  v a2s .  c om

    private static SimpleDateFormat getSimpleDateFormat(String strFormat) {
        if (strFormat != null && !"".equals(strFormat.trim())) {
            return new SimpleDateFormat(strFormat);
        } else {
            return new SimpleDateFormat();
        }
    }
}

Related

  1. toDate(String date, String format)
  2. toDate(String date, String format)
  3. toDate(String date, String format)
  4. toDate(String dateStr)
  5. toDate(String dateStr)
  6. toDate(String dateStr, String pattern)
  7. toDate(String dateString)
  8. toDate(String dateString)
  9. toDate(String dateString)