Java Date Parse getDatefromString(String dateStr)

Here you can find the source of getDatefromString(String dateStr)

Description

convert from MMM/dd/YYYY

License

Open Source License

Parameter

Parameter Description
dateStr a parameter

Exception

Parameter Description
ParseException an exception

Declaration

public static Date getDatefromString(String dateStr) throws ParseException 

Method Source Code


//package com.java2s;
import java.text.DateFormat;

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

import java.util.Date;

import java.util.Locale;

public class Main {
    public static final Date MAX_DATE = new Date(9999, 1, 1);

    /**/*from w w  w . j a v a2s  .  c om*/
     * convert from MMM/dd/YYYY
     * @param dateStr
     * @return
     * @throws ParseException 
     */
    public static Date getDatefromString(String dateStr) throws ParseException {
        String actualDate = "";
        String[] dates = dateStr.split("/");
        System.out.println("date leng" + dates.length);
        if (dates.length >= 3) {
            actualDate = dates[1] + "-" + dates[0] + "-" + dates[2];
            DateFormat mediumFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
            return mediumFormat.parse(actualDate);
        }
        return MAX_DATE;
    }
}

Related

  1. getDateFromString(final String inputStringDate, final String format)
  2. getDateFromString(String _date, String _format)
  3. getDateFromString(String date)
  4. getDateFromString(String date, String fmt)
  5. getDateFromString(String date, String pattern)
  6. getDateFromString(String dateStr, String datePattern)
  7. getDateFromString(String dateString)
  8. getDateFromString(String dateString)
  9. getDateFromString(String dateString)