Here you can find the source of parseDate(String dateStr, String dateFormat)
Parameter | Description |
---|---|
dateStr | Example 2012-12-15:10:10:10 |
dateFormat | Example yyyy-MM-dd HH:mm:ss |
Parameter | Description |
---|---|
ParseException | an exception |
public static Date parseDate(String dateStr, String dateFormat) throws ParseException
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**/*from w w w . j a v a 2s . co m*/ * Parse date based on date format yyyy/MM/dd-HH:mm:ss * @param dateStr * @return * @throws ParseException */ public static Date parseDate(String dateStr) throws ParseException { return parseDate(dateStr, "yyyy/MM/dd-HH:mm:ss"); } /** * Parse the date in string format based on date format and return a Date object * @param dateStr Example 2012-12-15:10:10:10 * @param dateFormat Example yyyy-MM-dd HH:mm:ss * @return * @throws ParseException */ public static Date parseDate(String dateStr, String dateFormat) throws ParseException { DateFormat format = new SimpleDateFormat(dateFormat); return format.parse(dateStr); } }