溫馨提示×

java如何獲取當前時間月份

小億
266
2024-08-12 13:06:35
欄目: 編程語言

在Java中獲取當前時間的月份可以使用java.time.LocalDatejava.time.Month類來實現。以下是一個示例代碼:

import java.time.LocalDate;
import java.time.Month;

public class Main {
    public static void main(String[] args) {
        // 獲取當前日期
        LocalDate currentDate = LocalDate.now();

        // 獲取當前月份
        Month currentMonth = currentDate.getMonth();

        System.out.println("當前月份為: " + currentMonth);
    }
}

在上面的代碼中,首先使用LocalDate.now()方法獲取當前日期,然后調用getMonth()方法獲取當前月份,并將其打印出來。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女