Saturday, October 18, 2025
HomeLanguagesJavaTemporalAdjusters firstDayOfNextMonth() method in Java with Examples

TemporalAdjusters firstDayOfNextMonth() method in Java with Examples

The firstDayOfNextMonth() method of a TemporalAdjusters class is used to return the “first day of next month” TemporalAdjuster object, which returns a new Date object set to the first day of the next month. Syntax:

public static TemporalAdjuster firstDayOfNextMonth()

Parameters: This method accepts nothing. Return value: This method returns the first day of next month adjuster, not null. Below programs illustrate the TemporalAdjusters.firstDayOfNextMonth() method: Program 1: 

Java




// Java program to demonstrate
// TemporalAdjusters.firstDayOfNextMonth()
 
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalAdjusters;
 
public class GFG {
    public static void main(String[] args)
    {
 
        // get TemporalAdjuster with first day
        // of next month adjuster
        TemporalAdjuster temporalAdjuster
            = TemporalAdjusters.firstDayOfNextMonth();
 
        // using adjuster for local date time
        LocalDate localDate
            = LocalDate.of(2020, 05, 11);
        LocalDate firstDayOfNextMonth
            = localDate.with(temporalAdjuster);
 
        // print
        System.out.println("First day of next "
                           + "month for localdate "
                           + localDate + ": "
                           + firstDayOfNextMonth);
    }
}


Output:

First day of next month for localdate 2020-05-11: 2020-06-01

Program 2: 

Java




// Java program to demonstrate
// TemporalAdjusters.firstDayOfNextMonth() method
 
import java.time.LocalDate;
import java.time.temporal.*;
 
public class GFG {
    public static void main(String[] args)
    {
 
        // get TemporalAdjuster with first day
        // of next month adjuster
        TemporalAdjuster temporalAdjuster
            = TemporalAdjusters
                  .firstDayOfNextMonth();
 
        // using adjuster for local date-time
        LocalDate localDate
            = LocalDate.of(2010, 12, 29);
        LocalDate firstDayOfNextMonth
            = localDate.with(temporalAdjuster);
 
        // print
        System.out.println(
            "First day of next "
            + "month for localdate "
            + localDate + ": "
            + firstDayOfNextMonth);
    }
}


Output:

First day of next month for localdate 2010-12-29: 2011-01-01

References: https://docs.oracle.com/javase/10/docs/api/java/time/format/TemporalAdjusters.html

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS