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

StringgetFriendlyLocalDateTime(Date date)
Return timestamp in human-readable form wrt local timezone
final SimpleDateFormat sdf = new SimpleDateFormat(
        friendlyDateFormat);
sdf.setTimeZone(TimeZone.getDefault());
return sdf.format(date);
StringdateTimeToString(final Date date)
date Time To String
if (date == null)
    return "Never";
return DateFormat.getDateTimeInstance().format(date);
StringdateToString(Date date)
date To String
if (date == null) {
    return null;
return format.format(date);
StringdatesToString(final Date start, final int duration)
dates To String
return new SimpleDateFormat("EEE @HH:mm").format(start) + " - "
        + duration + " min";
StringdatesToString(final Date start, final int duration)
dates To String
return new SimpleDateFormat("EEEEEEEE dd @HH:mm").format(start)
        + " - " + duration + " min";
StringconvertDateToString(Date date)
convert Date To String
SimpleDateFormat df = new SimpleDateFormat("yyyy-MMM-dd");
return df.format(date);
StringtoSimpleDateFormattedString(Date date)
to Simple Date Formatted String
try {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    return sdf.format(date);
} catch (Exception e) {
return null;
StringtoStringFromDate(Date date)
to String From Date
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
String return_date = sd.format(date);
return return_date;
StringtoUTCFormattedString(Date date)
to UTC Formatted String
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
return df.format(date);
voidupdateDate(DatePicker picker, Date date)
Convinient method to update a date in a DatePicker .
if (picker != null && date != null) {
    Calendar c = GregorianCalendar.getInstance();
    c.setTime(date);
    int y = c.get(Calendar.YEAR);
    int m = c.get(Calendar.MONTH);
    int d = c.get(Calendar.DAY_OF_MONTH);
    picker.updateDate(y, m, d);