Android examples for java.util:Date Parse
Parse string To Date
import android.text.TextUtils; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; public class Main{ public static Date stringToDate(String dateStr, String formatStr) { DateFormat sdf = new SimpleDateFormat(formatStr); Date date = null;/*from w w w .j a v a 2 s . c o m*/ try { date = sdf.parse(dateStr); } catch (Exception e) { e.printStackTrace(); } return date; } public static Date stringToDate(String mFirstDate, SimpleDateFormat yearformat) { Date parse = null; try { if (mFirstDate != null) { parse = yearformat.parse(mFirstDate); } } catch (ParseException e) { e.printStackTrace(); } return parse; } }