Java代码计算指定年月日的天数
import java.time.LocalDate; import java.time.format.DateTimeFormatter;
public class DayCounter {
public static void main(String[] args) {
String dateInput = '2021-05-12'; // 日期输入格式为 'yyyy-MM-dd'
LocalDate date = LocalDate.parse(dateInput, DateTimeFormatter.ISO_LOCAL_DATE);
int days = date.lengthOfMonth();
System.out.println('该月的天数为:' + days);
}
}
原文地址: https://www.cveoy.top/t/topic/mImL 著作权归作者所有。请勿转载和采集!