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

StringformatDate(Calendar cal)
format Date
StringBuffer sb = new StringBuffer();
sb.append(cal.get(cal.YEAR)).append("-").append(1 + cal.get(cal.MONTH)).append("-")
        .append(cal.get(cal.DAY_OF_MONTH)).append("|").append(translateToDayNumber(cal));
return sb.toString();
StringformatDate(Calendar cal)
format Date
StringBuilder sb = new StringBuilder();
sb.append(cal.get(Calendar.YEAR) + "");
sb.append('-');
sb.append(pad2(cal.get(Calendar.MONTH) + 1));
sb.append('-');
sb.append(pad2(cal.get(Calendar.DAY_OF_MONTH)));
sb.append('T');
sb.append(pad2(cal.get(Calendar.HOUR_OF_DAY)));
...
StringformatDate(Calendar calendar)
Formatta una data col seguente pattern dd/MM/yyyy HH:MM:SS
String stringDate = null;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
if (calendar != null) {
    stringDate = sdf.format(calendar.getTime());
return stringDate;
StringformatDate(Calendar date)
format Date
return DAY_FORMAT.format(date.getTime());
StringformatDate(Calendar date)
Format a date to YYYY-MM-dd format
return dateFormatter.format(date.getTime());
StringformatDate(Calendar date)
Format a date to standard format.
StringBuffer ret = new StringBuffer();
int tt = 0;
ret.append(date.get(Calendar.YEAR));
ret.append("-");
tt = date.get(Calendar.MONTH) + 1;
if (tt < 10) {
    ret.append("0");
ret.append(tt).append("-");
tt = date.get(Calendar.DAY_OF_MONTH);
if (tt < 10) {
    ret.append("0");
ret.append(tt);
return ret.toString();
StringformatDate(Calendar date, int precision)
Format a Calendar date with a given precision.
assert date != null;
switch (precision) {
case Calendar.MILLISECOND:
    return String.format("%04d-%02d-%02d %02d:%02d:%02d.%03d", date.get(Calendar.YEAR),
            date.get(Calendar.MONTH) + 1, date.get(Calendar.DAY_OF_MONTH), date.get(Calendar.HOUR_OF_DAY),
            date.get(Calendar.MINUTE), date.get(Calendar.SECOND), date.get(Calendar.MILLISECOND));
case Calendar.SECOND:
    return String.format("%04d-%02d-%02d %02d:%02d:%02d", date.get(Calendar.YEAR),
...
StringFormatDate(Calendar p_date, String p_separator)
This is a wrapper to convert calls from existing code to the new FormatData() that takes the p_dateOrderType parameter.
return FormatDate(p_date, p_separator, DATE_ORDER_NUMERIC);
StringformatDate(String formats, Calendar date)
format Date
String formatValue = formats;
if (formats.startsWith(DATE_FORMAT_PREFIX)) {
    while (true) {
        if (!formatValue.contains(DATE_FORMAT_PREFIX)) {
            break;
        String format = formatValue.substring(formatValue.indexOf(DATE_FORMAT_PREFIX),
                formatValue.indexOf(DATE_FORMAT_PREFIX) + 3);
...
StringformatDateTime(Calendar cal)
format Date Time
StringBuffer sb = new StringBuffer();
sb.append(cal.get(cal.YEAR)).append("-").append(1 + cal.get(cal.MONTH)).append("-")
        .append(cal.get(cal.DAY_OF_MONTH)).append(":").append(cal.get(cal.HOUR_OF_DAY)).append(":")
        .append(cal.get(cal.MINUTE)).append(":").append(cal.get(cal.SECOND)).append(":")
        .append(cal.get(cal.MILLISECOND)).append("|").append(translateToMilliseconds(cal));
return sb.toString();