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

StringformatDateTimeUTC(Calendar datetime)
Format a date-time into UTC format.
String ret = "";
int tt = 0;
ret += datetime.get(Calendar.YEAR);
tt = datetime.get(Calendar.MONTH) + 1;
ret += tt < 10 ? "0" + tt : "" + tt;
tt = datetime.get(Calendar.DAY_OF_MONTH);
ret += (tt < 10 ? "0" + tt : "" + tt) + "T";
tt = datetime.get(Calendar.HOUR_OF_DAY);
...
StringformatDay(java.util.Calendar d)
format Day
return yyyyMMdd.format(d.getTime());
StringformatDuration(Calendar t1, Calendar t2, boolean precise)
format Duration
return formatDuration(getDuration(t1, t2), precise);
StringformatRfc3339Calendar(Calendar cal)
format Rfc Calendar
return formatRfc3339Date(cal.getTime(), cal.getTimeZone());
voidformatTime(Calendar cal, StringBuffer sb)
format Time
int h = cal.get(Calendar.HOUR_OF_DAY);
int m = cal.get(Calendar.MINUTE);
int s = cal.get(Calendar.SECOND);
int ms = cal.get(Calendar.MILLISECOND);
if (h < 10) {
    sb.append('0');
sb.append(h);
...
StringformatToHTTPDate(Calendar calendar)
format To HTTP Date
return String.format(Locale.ENGLISH, FORMAT_HTTPDATE, calendar);
StringgetDate(Calendar cal, String dateFormat)
get Date
Calendar toUse = Calendar.getInstance(_locale);
toUse.setTime(cal.getTime());
toUse.add(Calendar.MONTH, -1);
SimpleDateFormat df = null;
if (_dateFormatMap.get(dateFormat) != null) {
    df = (SimpleDateFormat) _dateFormatMap.get(dateFormat);
} else {
    df = new SimpleDateFormat(dateFormat, _locale);
...
StringgetDate(Calendar cal, String dateFormat)
get Date
Calendar toUse = (Calendar) cal.clone();
toUse.add(Calendar.MONTH, -1);
SimpleDateFormat df = new SimpleDateFormat(dateFormat);
df.setLenient(true);
return df.format(cal.getTime());
voidprint(Calendar[] calendar)
print
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
System.out.print(
        " - FROM: " + sdf.format(calendar[0].getTime()) + " - TO: " + sdf.format(calendar[1].getTime()));
voidprintCalendar(Calendar cal)
print Calendar
if (cal != null) {
    System.out.println(sdf2.format(cal.getTime()));