在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);
}
}
}
这段代码会输出当月的每一天的日期号。