温馨提示×

Java如何获得当前月份

小亿
104
2024-01-26 18:45:24
栏目: 编程语言

在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);
    }
}

运行以上代码会输出当前的月份。

0