溫馨提示×

java如何獲取當月天數

小樊
325
2024-07-13 10:34:26
欄目: 編程語言

在Java中,可以使用java.time.YearMonth類來獲取當月的天數。

import java.time.YearMonth;

public class Main {
    public static void main(String[] args) {
        YearMonth yearMonth = YearMonth.now();
        int daysInMonth = yearMonth.lengthOfMonth();
        
        System.out.println("當前月份的天數:" + daysInMonth);
    }
}

以上代碼中,首先創建了一個YearMonth對象表示當前月份,然后使用lengthOfMonth()方法獲取當月的天數。最后打印出當月的天數。

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