Java LocalDate Calculate getFirstDayOfTheMonth(final LocalDate date)

Here you can find the source of getFirstDayOfTheMonth(final LocalDate date)

Description

Returns a leveled date representing the first day of the month based on a specified date.

License

Open Source License

Parameter

Parameter Description
date the base date to work from

Return

The last day of the month and year specified

Declaration

public static LocalDate getFirstDayOfTheMonth(final LocalDate date) 

Method Source Code

//package com.java2s;
/*/*from www  . j ava  2 s  .c  om*/
 * jGnash, a personal finance application
 * Copyright (C) 2001-2019 Craig Cavanaugh
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.time.LocalDate;

import java.time.temporal.TemporalAdjusters;

public class Main {
    /**
     * Returns a leveled date representing the first day of the month based on a
     * specified date.
     *
     * @param date the base date to work from
     * @return The last day of the month and year specified
     */
    public static LocalDate getFirstDayOfTheMonth(final LocalDate date) {
        return date.with(TemporalAdjusters.firstDayOfMonth());
    }

    /**
     * Returns a date representing the first day of the month.
     *
     * @param month The month (index starts at 1)
     * @param year  The year (index starts at 1)
     * @return The last day of the month and year specified
     */
    private static LocalDate getFirstDayOfTheMonth(final int month, final int year) {
        return LocalDate.of(year, month, 1);
    }
}

Related

  1. getDate(final LocalDate localDate)
  2. getDate(LocalDate d, String tzId)
  3. getDateCriteria(LocalDate startDate, LocalDate endDate)
  4. getDateStart(LocalDate localDate)
  5. getEndDateOfMonth(LocalDate date)
  6. getLastDayInMonth(LocalDate localDate)
  7. getLastDayOfTheQuarter(final LocalDate date)
  8. getLocalDateBydayAndWeek(LocalDate localDate, int weekNumber, int dayNumber)
  9. getLrsLocalDate(String lbdcDate)