Android Utililty Methods Date String Parse

List of utility methods to do Date String Parse

Description

The list of methods to do Date String Parse are organized into topic(s).

Method

DateparseSimpleDate(String dateString)
parse Simple Date
SimpleDateFormat formatter = new SimpleDateFormat("DD/MM/yy",
        Locale.UK);
Date date = null;
try {
    date = (Date) formatter.parse(dateString);
} catch (ParseException e) {
    e.printStackTrace();
return date;
DateparseUTCFormattedDateString(String dateString)
parse UTC Formatted Date String
SimpleDateFormat formatter = new SimpleDateFormat(
        "yyyy-MM-dd'T'HH:mm'Z'");
Date date = null;
try {
    date = formatter.parse(dateString);
} catch (ParseException e) {
    Log.e(DateTimeUtil.class.getSimpleName(),
            "Failed to parse date");
...
DateparseYoutubeDate(String rawDate)
parse Youtube Date
final String TAG = "StringUtil.parseYoutubeDate";
String pattern = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.US);
String minusTimezone = rawDate.substring(0, rawDate.indexOf('.'));
String cleanSpecials = minusTimezone.replace('T', ' ');
try {
    return sdf.parse(cleanSpecials);
} catch (ParseException pe) {
...
DatestringToDate(String str)
string To Date
if (isBlank(str)) {
    return null;
try {
    return format.parse(str);
} catch (ParseException e) {
    return null;
DatetoDate(String sdate)
to Date
try {
    return dateFormater.parse(sdate);
} catch (ParseException e) {
    try {
        return dateFormater.parse(new Date(toLong(sdate) * 1000L)
                .toGMTString());
    } catch (ParseException e1) {
        return null;
...
DatetoDate(String sdate)
to Date
try {
    return dateFormater.get().parse(sdate);
} catch (ParseException e) {
    return null;
StringtoDateFormat(String d, String delim)
to Date Format
StringBuffer sb = new StringBuffer();
if (d == null || d.equals("") || d.length() != 8) {
    return d;
sb.append(d.substring(0, 4));
sb.append(delim);
sb.append(d.substring(4, 6));
sb.append(delim);
...
DateparseDate(CharSequence input)
parse Date
return parseDate(input, null);
DateparseDate(CharSequence input, Date defaultDate)
parse Date
if (input == null)
    return defaultDate;
else {
    try {
        return dateFormatter.parse(input.toString());
    } catch (Exception e) {
        return null;
DateparseDate(CharSequence input, String pattern, Date defaultDate)
parse Date
if (input == null)
    return defaultDate;
else {
    try {
        if (pattern != null)
            return new SimpleDateFormat(pattern).parse(input
                    .toString());
        else {
...