在Java中,可以使用java.util.Calendar
類來獲取當月每天的日期號。以下是一個示例代碼:
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int day = 1; day <= daysInMonth; day++) {
calendar.set(Calendar.DAY_OF_MONTH, day);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println(dayOfMonth);
}
}
}
這段代碼會輸出當月的每一天的日期號。