在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); } }
运行以上代码会输出当前的月份。