您好,登錄后才能下訂單哦!
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
// 設(shè)置月份,注意月份從0開始計數(shù),即0代表1月,1代表2月,以此類推
int month = 2; // 獲取3月份的天數(shù)
calendar.set(Calendar.MONTH, month);
// 獲取該月份的天數(shù)
int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
System.out.println("Number of days in the month: " + daysInMonth);
}
}
在上面的示例代碼中,我們使用java.util.Calendar
類來獲取特定月份的天數(shù)。首先,我們創(chuàng)建一個Calendar
實(shí)例并設(shè)置要獲取天數(shù)的月份。然后,我們通過調(diào)用getActualMaximum(Calendar.DAY_OF_MONTH)
方法來獲取該月份的天數(shù),并將結(jié)果打印輸出。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。