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

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

Description

str To Date

License

Apache License

Declaration

public static Date strToDate(String dateStr, String format) throws ParseException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

import java.util.Date;

public class Main {
    public static String yyyyMMdd = "yyyyMMdd";

    public static Date strToDate(String dateStr) throws ParseException {
        SimpleDateFormat formater = new SimpleDateFormat(yyyyMMdd);
        Date date = formater.parse(dateStr);
        return date;
    }//from   w w  w .  j  av a 2  s  . c  om

    public static Date strToDate(String dateStr, String format) throws ParseException {
        SimpleDateFormat formater = new SimpleDateFormat(format);
        Date date = formater.parse(dateStr);
        return date;
    }
}

Related

  1. strToDate(String date)
  2. strToDate(String date, String pattern)
  3. StrToDate(String dateFormat)
  4. strToDate(String dateInString)
  5. strToDate(String dateStr, String dateFormat)
  6. strToDate(String format, String dateStr)
  7. strToDate(String i_StrDate, String i_Format)
  8. strToDate(String input, String format)
  9. strToDate(String s, Date defaultValue)