Android Utililty Methods Date to String Convert

List of utility methods to do Date to String Convert

Description

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

Method

StringgetStringFromDate(Date date)
get String From Date, "EEE MMM dd HH:mm:ss ZZZZZ yyyy"
return sf.format(date);
StringjavaDateToIso8601(Date date)
java Date To Iso
if (date == null)
    return "";
DateFormat formatter = ISO8601Format.get();
return formatter.format(date);
StringjavaDateToTimeSpan(final Date date)
java Date To Time Span
if (date == null)
    return "";
long passedTime = date.getTime();
long currentTime = System.currentTimeMillis();
long secondsSince = (currentTime - passedTime) / 1000;
if (secondsSince < 60)
    return WordPress.getContext().getString(
            R.string.reader_timespan_now);
...
DatetoGMTDate(Date localDate)
to GMT Date
return new Date();
StringtoString(Date date)
to String
if (date == null)
    return "";
SimpleDateFormat lv_formatter;
lv_formatter = new SimpleDateFormat(kSimpleDateFormat);
lv_formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
return lv_formatter.format(date);
StringgetStrFromDate(Date date)
get Str From Date
Date curDate = date;
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("yyyy-MM-dd");
today = sdf.format(curDate);
return today;
StringdateToString(Date date)
date To String
return dateToString(DEFAULT_DATE_FORMAT, date);
StringdateToString(String format, String date)
date To String
long time = getTimeInMillis(date);
calendar.clear();
calendar.setTimeInMillis(time);
return dateToString(format, calendar.getTime());
StringdateToString(String format, Date date)
date To String
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(date);
StringdateToString(Date time)
date To String, "yyyy-MM-dd HH:mm:ss"
SimpleDateFormat formatter;
formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String ctime = formatter.format(time);
return ctime;