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

longISO8601ToTimestamp(String aDate)
ISO To Timestamp
long result = 0;
SimpleDateFormat format = new SimpleDateFormat(
        "yyyy-MM-dd'T'HH:mm:ssZ");
try {
    result = new Timestamp(format.parse(aDate).getTime()).getTime();
} catch (ParseException e) {
    e.printStackTrace();
return result;
DateParseStringToDate(String date)
Parse String To Date
Date result = null;
if (date != null && !date.equals("")) {
    String parse = date;
    parse = parse.replaceFirst("^[0-9]{4}([^0-9]?)", "yyyy$1");
    parse = parse.replaceFirst("^[0-9]{2}([^0-9]?)", "yy$1");
    parse = parse.replaceFirst("([^0-9]?)[0-9]{1,2}([^0-9]?)",
            "$1MM$2");
    parse = parse.replaceFirst("([^0-9]?)[0-9]{1,2}( ?)", "$1dd$2");
...
DategetDateByTime(String time)
get Date By Time
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date date;
try {
    if (TextUtils.isEmpty(time)) {
        return null;
    date = sdf.parse(time);
    return date;
...
booleanisDateString(String dirtyDate)
is Date String
int len = dirtyDate.length();
if (len == 10) {
    for (int i = 0; i < len; i++) {
        if (i == 4 || i == 7) {
            if (dirtyDate.charAt(i) != '-')
                return false;
        } else {
            if (!Character.isDigit(dirtyDate.charAt(i)))
...
booleanisDateTimeString(String dirtyDateTime)
is Date Time String
int len = dirtyDateTime.length();
if (len != 10 && len != 19)
    return false;
if (!isDateString(dirtyDateTime.substring(0, 10)))
    return false;
if (len == 10)
    return true;
if (dirtyDateTime.charAt(10) != ' ')
...
Dateparse(String date)
parse
return parse(date, "yyyy-MM-dd");
Dateparse(String date, String format)
parse
DateFormat sdf = new SimpleDateFormat(format);
try {
    return sdf.parse(date);
} catch (ParseException e) {
return null;
Dateparse(String date, boolean isDateOnly)
parse
if (isDateOnly) {
    return parse(date);
} else {
    return parse(date, "yyyy-MM-dd HH:mm");
Dateparse(String dateString, String dateFormat)
parse
if (StringUtil.isEmpty(dateString)
        || StringUtil.isEmpty(dateFormat)) {
    return null;
SimpleDateFormat format = new SimpleDateFormat(dateFormat,
        Locale.ENGLISH);
Date date = null;
try {
...
java.util.Dateparse(String src)
parse
try {
    return DateFormat.getDateInstance().parse(src);
} catch (ParseException e) {
    return DateFormat.getInstance().getCalendar().getTime();