Javaでは、現在の月を取得する方法は何ですか?

Javaの中では、現在の月を取得するためにjava.time.LocalDateクラスを使用することができます。以下は例のコードです:

import java.time.LocalDate;

public class Main {
    public static void main(String[] args) {
        LocalDate currentDate = LocalDate.now();
        int currentMonth = currentDate.getMonthValue();
        System.out.println("当前月份:" + currentMonth);
    }
}

このコードを実行すると、現在の月が出力されます。

bannerAds