/** * Formats a date or time, which is the standard millis * since January 1, 1970, 00:00:00 GMT. * <p>Example: using the US locale: * "yyyy.MM.dd G 'at' HH:mm:ss zzz" ->> 1996.07.10 AD at 15:08:56 PDT * @param cal the calendar whose date-time value is to be formatted into a date-time string * @param toAppendTo where the new date-time text is to be appended * @param pos the formatting position. On input: an alignment field, * if desired. On output: the offsets of the alignment field. * @return the formatted date-time string. * @see DateFormat * @stable ICU 2.0 */ public StringBuffer format(Calendar cal, StringBuffer toAppendTo, FieldPosition pos) { StringBuffer result; FieldPosition jdkPos = toJDKFieldPosition(pos); synchronized(dateFormat) { java.util.Calendar oldCal = dateFormat.getCalendar(); dateFormat.setCalendar(cal.calendar); result = dateFormat.format(cal.getTime(), toAppendTo, jdkPos); dateFormat.setCalendar(oldCal); } if (jdkPos != null) { pos.setBeginIndex(jdkPos.getBeginIndex()); pos.setEndIndex(jdkPos.getEndIndex()); } return result; }
/** * Formats a date or time, which is the standard millis * since January 1, 1970, 00:00:00 GMT. * <p>Example: using the US locale: * "yyyy.MM.dd G 'at' HH:mm:ss zzz" ->> 1996.07.10 AD at 15:08:56 PDT * @param cal the calendar whose date-time value is to be formatted into a date-time string * @param toAppendTo where the new date-time text is to be appended * @param pos the formatting position. On input: an alignment field, * if desired. On output: the offsets of the alignment field. * @return the formatted date-time string. * @see DateFormat * @stable ICU 2.0 */ public StringBuffer format(Calendar cal, StringBuffer toAppendTo, FieldPosition pos) { StringBuffer result; FieldPosition jdkPos = toJDKFieldPosition(pos); synchronized(dateFormat) { java.util.Calendar oldCal = dateFormat.getCalendar(); dateFormat.setCalendar(cal.calendar); result = dateFormat.format(cal.getTime(), toAppendTo, jdkPos); dateFormat.setCalendar(oldCal); } if (jdkPos != null) { pos.setBeginIndex(jdkPos.getBeginIndex()); pos.setEndIndex(jdkPos.getEndIndex()); } return result; }