Here you can find the source of getDatefromString(String dateStr)
Parameter | Description |
---|---|
dateStr | a parameter |
Parameter | Description |
---|---|
ParseException | an exception |
public static Date getDatefromString(String dateStr) throws ParseException
//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; } }