Java Calendar Month setDate(Calendar calendar, int month, int date)

Here you can find the source of setDate(Calendar calendar, int month, int date)

Description

Sets the given Calendar 's instance to a specific date.

License

Open Source License

Parameter

Parameter Description
calendar the Calendar 's instance.
month the month.
date the day of the month.

Declaration

private static void setDate(Calendar calendar, int month, int date) 

Method Source Code


//package com.java2s;
/*/*  w w w .ja v  a2s  .co  m*/
 * Copyright (C) 2014 Celestibytes
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 */

import java.util.Calendar;

public class Main {
    /**
     * Sets the given {@link Calendar}'s instance to a specific date.
     *
     * @param calendar
     *            the {@link Calendar}'s instance.
     * @param month
     *            the month.
     * @param date
     *            the day of the month.
     */
    private static void setDate(Calendar calendar, int month, int date) {
        calendar.clear();
        calendar.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
        calendar.set(Calendar.MONTH, month);
        calendar.set(Calendar.DATE, date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
    }
}

Related

  1. month(Calendar date)
  2. numberOfDaysInMonth(Calendar cal)
  3. sameMonth(Calendar one, Calendar two)
  4. setDate(Calendar cal, int month, int date)
  5. setDate(Calendar cal, int month, int date, boolean endOfDay)
  6. setTimeAsFirstDayOfMonth(Calendar calendar)
  7. subtractMonths(Calendar date, int months)