Android Utililty Methods Calendar Format

List of utility methods to do Calendar Format

Description

The list of methods to do Calendar Format are organized into topic(s).

Method

StringformateCalDavDue(Calendar c)
formate Cal Dav Due
return c == null ? null : caldavDueFormat.format(c.getTime());
StringgetUniversalDateStamp(Calendar cal)
Get current time stamp in universal format
Format: yyyy-mm-ddThh:mm:ssZ
e.g.: 1999-09-09T13:10:40Z
String year = String.valueOf(cal.get(Calendar.YEAR));
String month = String.valueOf(cal.get(Calendar.MONTH) + 1);
if (month.length() == 1) {
    month = "0" + month;
String day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
if (day.length() == 1) {
    day = "0" + day;
...
StringgetFormattedTime(Context context, Calendar time)
get Formatted Time
String skeleton = DateFormat.is24HourFormat(context) ? "EHm"
        : "Ehma";
String pattern = DateFormat.getBestDateTimePattern(
        Locale.getDefault(), skeleton);
return (String) DateFormat.format(pattern, time);
StringgetFormattedTime(Context context, Calendar time)
get Formatted Time
String skeleton = DateFormat.is24HourFormat(context) ? "EHm"
        : "Ehma";
String pattern = DateFormat.getBestDateTimePattern(
        Locale.getDefault(), skeleton);
return (String) DateFormat.format(pattern, time);
Stringcalendar2string(Calendar calendar, String formatString)
calendarstring
return new SimpleDateFormat(formatString)
        .format(calendar.getTime());
Stringformat(Calendar cal, String format, Locale locale)
format
SimpleDateFormat formatter = new SimpleDateFormat(format, locale);
return formatter.format(cal.getTime());
CalendargetCalendarFromDateString(String dateString, String format, Locale locale)
get Calendar From Date String
SimpleDateFormat formatter = new SimpleDateFormat(format, locale);
Calendar cal = Calendar.getInstance();
try {
    cal.setTime(formatter.parse(dateString));
} catch (ParseException e) {
    DebugLog.e("ParseException");
    return null;
return cal;
StringgetFormatedDate(Calendar c, String format)
get Formated Date
try {
    Date d = new Date(c.getTimeInMillis());
    SimpleDateFormat dateFormat = new SimpleDateFormat(format);
    return dateFormat.format(d);
} catch (Exception e) {
    return new String();
Calendarstring2calendar(String s, String formatString)
stringcalendar
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(formatString);
Date d = null;
try {
    d = sdf.parse(s);
} catch (ParseException ignore) {
calendar.setTime(d);
...
StringtoSimpleDate(Calendar calendar, String format)
Format a calendar date to a string with a certain format.
SimpleDateFormat simpleDate = new SimpleDateFormat(format);
String simpleDateString = simpleDate.format(calendar.getTime());
return simpleDateString;