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

StringconvertDate(String YearMonthDay)
convert Date
String txtDate = "";
String expectedPattern = "yyyy-MM-dd";
SimpleDateFormat formatter = new SimpleDateFormat(expectedPattern);
Date date;
try {
    date = formatter.parse(YearMonthDay);
    DateFormat df = new SimpleDateFormat("MMMM dd,yyyy");
    txtDate = df.format(date);
...
StringconvertDateStringToDash(String MonthDayYear)
convert Date String To Dash
String convertedDate = "";
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
Date date;
try {
    date = formatter.parse(MonthDayYear);
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    convertedDate = df.format(date);
} catch (Exception e) {
...
longconvertDateStringToLong(String date, String format)
convert Date String To Long
SimpleDateFormat sdf = new SimpleDateFormat(format);
long time = -1;
try {
    time = sdf.parse(date).getTime();
} catch (ParseException e) {
    e.printStackTrace();
return time;
...
StringconvertDateTime( String YearMonthDayHourMinuteSeconds)
convert Date Time
String txtDate = "";
String expectedPattern = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat formatter = new SimpleDateFormat(expectedPattern);
Date date;
try {
    date = formatter.parse(YearMonthDayHourMinuteSeconds);
    DateFormat df = new SimpleDateFormat("MMMM dd,yyyy @ HH:mm");
    txtDate = df.format(date);
...
StringconvertToDate(String dateString)
convert To Date
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMMM-yy");
Date convertedDate = new Date();
try {
    convertedDate = dateFormat.parse(dateString);
} catch (ParseException e) {
    e.printStackTrace();
return convertedDate.toLocaleString();
...
DategetDateFromString(String format, String dateString)
get Date From String
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.parse(dateString);
HashMapgetDateFromLJString( String dateString)
get Date From LJ String
final HashMap<String, Object> result = new HashMap<String, Object>();
if (dateString == null || dateString.length() == 0) {
    return result;
final String[] dateTime = dateString.split(" ");
final String[] dateItems = dateTime[0].split("-");
result.put(YEAR, dateItems[0]);
result.put(MONTH, dateItems[1]);
...
DategetDateFromString(String dateString)
get Date From String
SimpleDateFormat sdf = new SimpleDateFormat(
        "yyyy-MM-dd'T'hh:mm:ss.S'Z'");
return sdf.parse(dateString);
DateparseRFC3339Date(String date)
parse RFC Date
Date result = null;
SimpleDateFormat format = RFC3339Formatter.get();
boolean isLocal = date.endsWith("Z");
if (date.contains(".")) {
    int fracIndex = date.indexOf(".");
    String first = date.substring(0, fracIndex);
    String second = null;
    if (isLocal) {
...
DateparseRFC822Date(String date)
parse RFC Date
Date result = null;
if (date.contains("PDT")) {
    date = date.replace("PDT", "PST8PDT");
if (date.contains(",")) {
    date = date.substring(date.indexOf(",") + 1).trim();
SimpleDateFormat format = RFC822Formatter.get();
...