Java 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

StringformatCalendar(Calendar calendar)
format Calendar
return formatDate(calendar.getTime());
StringformatCalendar(Calendar calendar)
format Calendar
final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS z";
SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat.format(calendar.getTime());
StringformatCalendar(Calendar calendar)
Calendar to String format.
if (calendar == null)
    return null;
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");
DATE_FORMAT.setCalendar(calendar);
return DATE_FORMAT.format(calendar.getTime());
StringformatCalendar(Calendar objCal, String strFormat)
format Calendar
if (objCal == null) {
    return null;
} else {
    SimpleDateFormat formatter = new SimpleDateFormat(strFormat);
    return formatter.format(objCal.getTime());
StringformatCalendarTS(Calendar value)
Formats the given value as a timestamp.
if (value == null) {
    return "";
return new SimpleDateFormat(TS_FMT).format(value.getTime());
StringformatCalendarXsdZulu(Calendar c, int millisDigits)
Format a Calendar object to a schema datetime string with time zone UTC Used by testConvertToDateTime().
String formatString = "yyyy-MM-dd'T'HH:mm:ss";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatString);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
StringBuffer sb = new StringBuffer(simpleDateFormat.format(c.getTime()));
sb.append(formatMillis(c.get(Calendar.MILLISECOND), millisDigits));
sb.append('Z');
return sb.toString();
StringformatDate(Calendar c)
returns yyyy-mm-dd format for given calendar object
if (c == null)
    return "??-??";
else
    return c.get(Calendar.YEAR) + "-" + String.format("%02d", (1 + c.get(Calendar.MONTH))) + "-"
            + String.format("%02d", c.get(Calendar.DAY_OF_MONTH));
StringformatDate(Calendar c)
format Date
return (new SimpleDateFormat("MM.dd.yy")).format(c.getTime());
StringformatDate(Calendar c)
format Date
if (c == null)
    return null;
SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
return df.format(c.getTime());
StringformatDate(Calendar cal)
Format calendar date
return new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(cal.getTime());