Here you can find the source of getDateFromString(String dateString, String dateFormat)
Parameter | Description |
---|---|
dateString | a parameter |
dateFormat | a parameter |
Parameter | Description |
---|---|
ParseException | an exception |
public static Date getDateFromString(String dateString, String dateFormat) throws ParseException
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static SimpleDateFormat yyyyMMddFormat = new SimpleDateFormat( "yyyy-MM-dd", Locale.ENGLISH); /**//ww w . ja va2 s . co m * Get the Date from String with custom format. Default format is yyyy-MM-dd * * @param dateString * @param dateFormat * @return * @throws ParseException */ public static Date getDateFromString(String dateString, String dateFormat) throws ParseException { SimpleDateFormat formatter; if (dateFormat == null) { formatter = yyyyMMddFormat; } else { formatter = new SimpleDateFormat(dateFormat, Locale.ENGLISH); } return formatter.parse(dateString); } }