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

StringdateToString(Date date, String format)
date To String
if (format == null)
    format = VN_DATE_FORMAT;
SimpleDateFormat ts = new SimpleDateFormat(format);
return ts.format(date);
DateparseStringToDate(String dateString, String sourceDateFormat, Locale locale)
Parse String to Date based on given date format using the provided Locale.
if (StringUtils.isNull(dateString)) {
    throw new NullPointerException("dateString cannot be null");
if (StringUtils.isEmpty(dateString)
        || StringUtils.isBlank(dateString)) {
    throw new IllegalArgumentException("dateString cannot be empty");
if (StringUtils.isNull(sourceDateFormat)) {
...
Dateparse2Date(SimpleDateFormat s, Object d)
parse Date
if (d instanceof String) {
    try {
        return s.parse(d.toString());
    } catch (ParseException e) {
        return new Date();
} else if (d instanceof Date) {
    return (Date) d;
...
java.util.DatestringToDate(String src, String format)
string To Date
try {
    src = src.trim();
    if (format == null)
        format = VN_DATE_FORMAT;
    SimpleDateFormat ts = new SimpleDateFormat(format);
    return ts.parse(src);
} catch (Exception e) {
    return null;
...
DatetoDateFromLongFormat(String date)
Returns a Java representation of a Facebook "long" date string, or the number of seconds since the epoch.
if (date == null)
    return null;
if (date.trim().matches("\\d+"))
    return new Date(Long.valueOf(date) * 1000L);
Date parsedDate = toDateWithFormatString(date,
        FACEBOOK_LONG_DATE_FORMAT);
if (parsedDate == null)
    parsedDate = toDateWithFormatString(date,
...
longparse(String aFormat, String date)
parse
SimpleDateFormat format = new SimpleDateFormat(aFormat);
try {
    return format.parse(date).getTime();
} catch (ParseException e) {
    e.printStackTrace();
    return 0;
DategetDate(String date)
get Date
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date d = formatter.parse(date);
Log.v(DateUtil.class.getName(), d.toString());
return d;
DategetDateFromString(String dateStr, String pattern)
get Date From String
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
Date resDate = null;
try {
    resDate = sdf.parse(dateStr);
} catch (Exception e) {
    e.printStackTrace();
return resDate;
...
DategetDateFromString(String string)
get Date From String
try {
    DateFormat m_ISO8601Local = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ss");
    return m_ISO8601Local.parse(string);
} catch (ParseException e) {
    return new Date(System.currentTimeMillis());
DategetDateObj(String argsDate, String split)
get Date Obj
String[] temp = argsDate.split(split);
int year = new Integer(temp[0]).intValue();
int month = new Integer(temp[1]).intValue();
int day = new Integer(temp[2]).intValue();
return getDateObj(year, month, day);