Android examples for java.util:Date Parse
Parses date string and converts to java.util.Date object with provided java.text.DateFormat
import android.util.Log; import java.text.DateFormat; import java.text.ParseException; import java.util.Date; public class Main{ /**//from w w w. j a va 2s . c om * Parses date string and converts to {@link java.util.Date} object with provided * {@link java.text.DateFormat} * * @param dateString * date string * @param dateFormat * date format used to parse date * @return {@link java.util.Date} representation of date string or null if parsing * fails */ public static Date toDate(String dateString, final DateFormat dateFormat) { Date date = null; if (dateString == null) { return null; } try { date = dateFormat.parse(dateString); } catch (ParseException ex) { Log.e(TAG, "Incorrect date format=" + dateString); } return date; } }