Java Calendar Add appendDate(StringBuffer buf, Calendar cal)

Here you can find the source of appendDate(StringBuffer buf, Calendar cal)

Description

Append date (in YYYY-MM-DD format) to specified buffer.

License

Open Source License

Declaration

private static StringBuffer appendDate(StringBuffer buf, Calendar cal) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

public class Main {
    /**//from   ww  w . ja va  2s.  com
     * Append date (in YYYY-MM-DD format) to specified buffer.
     */
    private static StringBuffer appendDate(StringBuffer buf, Calendar cal) {
        buf.append(cal.get(Calendar.YEAR)).append('-');
        appendInt2(buf, cal.get(Calendar.MONTH) + 1).append('-');
        appendInt2(buf, cal.get(Calendar.DAY_OF_MONTH));
        return buf;
    }

    /**
     * Same as {@link #formatInt2(int)} but appends to specified buffer.
     */
    private static StringBuffer appendInt2(StringBuffer buf, int n) {
        if (n < 10) {
            buf.append('0');
        }
        buf.append(n);
        return buf;
    }
}

Related

  1. addMonthDayToCal(Calendar cal, int month, int day)
  2. addSeconds(Calendar calendar, int amount)
  3. addToUTCMilliSeconds(int calendarTime, int actualValue)
  4. addWeekdays(Calendar cal, int days)
  5. addWorkdays(final Calendar calendar, final int dauer)
  6. appendDate(StringBuffer dateString, Calendar calendar)
  7. appendDate(StringBuffer sb, Calendar cal)
  8. appendEra(StringBuffer sb, Calendar cal)
  9. appendTime(Calendar value, StringBuffer dateString)