Java Utililty Methods Calendar to String

List of utility methods to do Calendar to String

Description

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

Method

StringdateToString(Calendar date, DateFormat format)
date To String
if (date == null)
    return null;
return format.format(date.getTime());
StringgetDateString(Calendar cal)
Returns the current date of the calendar in the m/d/yyyy format as a string
return (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH) + "/" + cal.get(Calendar.YEAR);
StringgetDateString(Calendar cal)
get Date String
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONDAY) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);
return year + "-" + month + "-" + day;
StringgetDateString(Calendar calendar)
get Date String
StringBuffer sb = new StringBuffer();
sb.append(calendar.get(Calendar.YEAR)).append("-");
int month = calendar.get(Calendar.MONTH) + 1;
if (month < 10)
    sb.append("0");
sb.append(month).append("-");
int day = calendar.get(Calendar.DAY_OF_MONTH);
if (day < 10)
...
StringgetDateToString(Calendar argCal)
Return YYYYMMDD
Calendar cal = argCal;
if (cal == null) {
    cal = new GregorianCalendar();
String date = "" + cal.get(Calendar.YEAR) + DATE_SEPARATOR;
if (cal.get(Calendar.MONTH) + 1 < 10) {
    date += "0";
date += (cal.get(Calendar.MONTH) + 1) + DATE_SEPARATOR;
if (cal.get(Calendar.DAY_OF_MONTH) < 10) {
    date += "0";
date += cal.get(Calendar.DAY_OF_MONTH);
return date;
StringgetString(Calendar calendar)
Return String object from Calendar @param calendar.
return getString(PATTERN_DEFAULT, calendar);
StringtoString(Calendar c)
to String
return getDateFormat().format(c.getTime());
StringtoString(Calendar cal)
Get a String representation of the Calendar with its date and time
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
return sdf.format(cal.getTime());
StringtoString(Calendar cal)
to String
String timeZoneId = cal.getTimeZone().getID();
if (timeZoneId.equals("UTC")) {
    return utcFormat.format(cal.getTime());
} else if (timeZoneId.equals("TAI")) {
    return taiFormat.format(cal.getTime()) + "-0000" + (cal.getTimeZone().getRawOffset() / 1000);
} else {
    return localFormat.format(cal.getTime());
StringtoString(Calendar cal)
Converts a Calendar to its CMISQL string representation.
StringBuilder buf = new StringBuilder(28);
toString(cal, buf);
return buf.toString();