Java Calendar Month getFirstDayOfMonth(final Calendar calendar, final Date date)

Here you can find the source of getFirstDayOfMonth(final Calendar calendar, final Date date)

Description

Get the first day of the input date's month

License

Apache License

Parameter

Parameter Description
calendar Calendar object
date The date to find out its first day of that month

Return

The first day in the month

Declaration

public static Date getFirstDayOfMonth(final Calendar calendar,
        final Date date) 

Method Source Code

//package com.java2s;
/**//from  w  ww . j ava2  s  .c o  m
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Calendar;

import java.util.Date;

public class Main {
    /**
     * Get the first day of the input date's month
     * @param calendar Calendar object
     * @param date The date to find out its first day of that month
     * @return The first day in the month
     */
    public static Date getFirstDayOfMonth(final Calendar calendar,
            final Date date) {

        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);

        Date firstDayInMonth = calendar.getTime();
        return firstDayInMonth;
    }
}

Related

  1. getDayOfMonthPostfix(Calendar cal)
  2. getDaysInMonth(Calendar cal)
  3. getFirstDateOfMonth(Calendar calendar)
  4. getFirstDayOfMonth(Calendar c)
  5. getFirstDayOfMonth(Calendar cal)
  6. getLastDateOfMonth(Calendar calendar)
  7. getLastDayOfMonth(Calendar c)
  8. getLastDayOfMonth(Calendar c)
  9. getLastDayOfMonth(Calendar calendar)