Java Utililty Methods Calendar Add

List of utility methods to do Calendar Add

Description

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

Method

CalendaraddMilliseconds(Calendar calendar, Long amount)
add Milliseconds
if (amount != null) {
    calendar.add(Calendar.MILLISECOND, (int) amount.floatValue());
return calendar;
CalendaraddMonth(Calendar cal, int period)
add Month
Calendar cal2 = cal;
cal2.set(Calendar.MONTH, cal.get(Calendar.MONTH) + period);
return cal;
CalendaraddMonthDayToCal(Calendar cal, int month, int day)
add Month Day To Cal
Date d = new Date();
int daysToAdd = 0;
int currentMonth = cal.get(2);
long t = 0;
t = d.getTime();
if (month > 0) {
    for (int i = 0; i < month; i++) {
        if (currentMonth < 12) {
...
CalendaraddSeconds(Calendar calendar, int amount)
add Seconds
return add(calendar, Calendar.SECOND, amount);
longaddToUTCMilliSeconds(int calendarTime, int actualValue)
Add given minutes/hours/seconds to actual calendar time.
final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.add(calendarTime, actualValue);
return calendar.getTimeInMillis();
voidaddWeekdays(Calendar cal, int days)
add Weekdays
while (days > 0) {
    while (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
            || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        cal.add(Calendar.DATE, 1);
    cal.add(Calendar.DATE, 1);
    days--;
    while (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
...
voidaddWorkdays(final Calendar calendar, final int dauer)
add Workdays
int i = dauer;
while (i > 0) {
    calendar.add(Calendar.DATE, 1);
    final int day = calendar.get(Calendar.DAY_OF_WEEK);
    if (day != Calendar.SUNDAY && day != Calendar.SATURDAY) {
        i--;
StringBufferappendDate(StringBuffer buf, Calendar cal)
Append date (in YYYY-MM-DD format) to specified buffer.
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;
voidappendDate(StringBuffer dateString, Calendar calendar)
append Date
int year = calendar.get(Calendar.YEAR);
if (year < 1000) {
    dateString.append("0");
if (year < 100) {
    dateString.append("0");
if (year < 10) {
...
voidappendDate(StringBuffer sb, Calendar cal)
append Date
int l_year = cal.get(Calendar.YEAR);
int l_yearlen = String.valueOf(l_year).length();
for (int i = 4; i > l_yearlen; i--) {
    sb.append("0");
sb.append(l_year);
sb.append('-');
int l_month = cal.get(Calendar.MONTH) + 1;
...