Here you can find the source of getDateFromString(String _date, String _format)
Parameter | Description |
---|---|
_date | A string representing a date |
_format | A string of the date format |
public static Date getDateFromString(String _date, String _format)
//package com.java2s; //License from project: Mozilla Public License import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**//from www. ja va2 s. c o m * Convert a string to a specific format {@link Date} * @param _date A string representing a date * @param _format A string of the date format * @return a {@link Date} */ public static Date getDateFromString(String _date, String _format) { // Parse the String into a Date object. Date _return = null; // Check for null. if (_date == null) { return _return; } // Try to parse what we have into a legitimate Date. try { SimpleDateFormat date_format = new SimpleDateFormat(_format); _return = date_format.parse(_date); } catch (java.text.ParseException e) { e.printStackTrace(); } // Return the Date object. return _return; } }