Android Utililty Methods Date String to Date Convert

List of utility methods to do Date String to Date Convert

Description

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

Method

DateParseDate(String str)
Parse Date
SimpleDateFormat dateFormat = new SimpleDateFormat(
        "yyyy-MM-dd hh:mm:ss");
Date addTime = null;
try {
    addTime = dateFormat.parse(str);
} catch (ParseException e) {
    e.printStackTrace();
return addTime;
DateParseUTCDate(String str)
Parse UTC Date
SimpleDateFormat formatter = new SimpleDateFormat(
        "yyyy-MM-dd'T'HH:mm:ssZ", Locale.CHINA);
try {
    Date date = formatter.parse(str);
    return date;
} catch (ParseException e) {
    try {
        SimpleDateFormat formatter2 = new SimpleDateFormat(
...
StringformatToDate(String date)
format To Date
if (date == null) {
    return "";
} else {
    int index = date.indexOf(" ");
    return (index > 0 ? date.substring(0, index) : date)
            .replaceAll("/", "-");
DatefromStringFR(String dateString)
from String FR as format "dd/MM/yyyy"
return fromString(dateString, DATE_FORMAT_dd_MM_yyyy);
DatefromStringUS(String dateString)
from String US
return fromString(dateString, DATE_FORMAT_MM_dd_yyyy);
DategetDateFromString(String dateString, String dateFormat)
Get the Date from String with custom format.
SimpleDateFormat formatter;
if (dateFormat == null) {
    formatter = yyyyMMddFormat;
} else {
    formatter = new SimpleDateFormat(dateFormat, Locale.ENGLISH);
return formatter.parse(dateString);
StringgetDefaultDateTimeString(String date, Locale locale)
get Default Date Time String
try {
    long millis = Long.parseLong(date);
    return getDateTimeString(new Date(millis), DateFormat.DEFAULT,
            locale);
} catch (Exception e) {
    return "";
StringgetShortDateTimeString(String date, Locale locale)
get Short Date Time String
try {
    long millis = Long.parseLong(date);
    return getDateTimeString(new Date(millis), DateFormat.SHORT,
            locale);
} catch (Exception e) {
    return "";
longiso8601ToTimestamp(final String strDate)
iso To Timestamp
Date date = iso8601ToJavaDate(strDate);
if (date == null)
    return 0;
return (date.getTime() / 1000);
longiso8601ToTimestamp(final String strDate)
iso To Timestamp
Date date = iso8601ToJavaDate(strDate);
if (date == null)
    return 0;
return (date.getTime() / 1000);