Ruang penulis
← Kembali ke jurnal
Java 8

How do I use TemporalAdjusters firstDayOfNextMonth() method?

The TemporalAdjusters.firstDayOfNextMonth() method is a useful method in java.time.temporal.TemporalAdjusters class in Java that adjusts the date to the first day of the next month. Here’s an example usage: package org.kodejava.datetime; import java.time.LocalDate; import java.time.temporal.TemporalAdjusters; public class FirstDayOfNextMonthExample { public static void main(String[] args) { // Get the current date LocalDate date = LocalDate.now(); // Adjust […]

DWayan · 17 Jan 2024 · 1 menit baca

Artikel oleh Wayan · Sumber: Kode Java ↗

Terjemahan artikel ini belum tersedia. Isi asli ditampilkan.

The TemporalAdjusters.firstDayOfNextMonth() method is a useful method in java.time.temporal.TemporalAdjusters class in Java that adjusts the date to the first day of the next month.

Here’s an example usage:

package org.kodejava.datetime;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;

public class FirstDayOfNextMonthExample {
    public static void main(String[] args) {
        // Get the current date
        LocalDate date = LocalDate.now();

        // Adjust to the first day of next month
        LocalDate firstDayOfNextMonth = date.with(TemporalAdjusters.firstDayOfNextMonth());

        System.out.println("Current date: " + date);
        System.out.println("First day of next month: " + firstDayOfNextMonth);
    }
}

Output:

Current date: 2024-01-18
First day of next month: 2024-02-01

In this example, LocalDate.now() is used to get the current date. Then .with(TemporalAdjusters.firstDayOfNextMonth()) is used to adjust the date to the first day of the next month.

← Jelajahi catatan lainnya