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

DateparseDateStrictly(String str, String... parsePatterns)

Parses a string representing a date by trying a variety of different parsers.

The parse will try each parse pattern in turn.

return parseDateWithLeniency(str, parsePatterns, false);
DateparseDateTime(String dateString)
parse Date Time, "E MMM d HH:mm:ss Z yyyy"
try {
    Log.v(TAG, String.format("in parseDateTime, dateString=%s",
            dateString));
    return TWITTER_DATE_FORMATTER.parse(dateString);
} catch (ParseException e) {
    Log.w(TAG, "Could not parse Twitter date string: " + dateString);
    return null;
DateparseDateWithLeniency(String str, String[] parsePatterns, boolean lenient)

Parses a string representing a date by trying a variety of different parsers.

The parse will try each parse pattern in turn.

if (str == null || parsePatterns == null) {
    throw new IllegalArgumentException(
            "Date and Patterns must not be null");
SimpleDateFormat parser = new SimpleDateFormat();
parser.setLenient(lenient);
ParsePosition pos = new ParsePosition(0);
for (String parsePattern : parsePatterns) {
...
DateparseLongFormat(String dateString)
parse Long Format
return parse(dateString, LOCAL_LONG_DATE_FORMAT);
DateparseSearchApiDateTime(String dateString)
parse Search Api Date Time, "E, d MMM yyyy HH:mm:ss Z"
try {
    return TWITTER_SEARCH_API_DATE_FORMATTER.parse(dateString);
} catch (ParseException e) {
    Log.w(TAG, "Could not parse Twitter search date string: "
            + dateString);
    return null;
CalendarparseString(String dateStr)
parse String
return parseString(dateStr, DEFAULTFORMAT);
CalendarparseString(String dateStr, String pattern)
parse String
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
Date date = sdf.parse(dateStr);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar;
DateparseStringToDate(String str)
parse String To Date
return parseDate(str, "yyyyMMddHHmm");
DateparseTM(String s, boolean end)
Parses a value that has a TM VR as a Date .
if (s == null || s.length() == 0) {
    return null;
Calendar c = new GregorianCalendar();
c.clear();
if (end) {
    setTo2359(c);
parseTM(c, s, 0, s.length());
return c.getTime();
DateparseDate(String date)
parse Date
try {
    SimpleDateFormat dateFormat = new SimpleDateFormat(
            DEFAULT_DATE_FORMAT);
    return dateFormat.parse(date);
} catch (ParseException e) {
    e.printStackTrace();
return new Date();
...