2工地上有个工程需要253天完工从今天是算起计算253天以后的工程竣工的日期。如果今天是2022年7月1日那么253天以后的日期为2023年3月11日。2工地上有个工程需要253天完工从今天是算起计算253天以后的工程竣工的日期是几月几号并格式化成XXXX年XX月XX日的形式输出。 提示: ① 调用LocalDate类的plusDays方法计算253以后的日期。 使用DateTimeFormatt
代码如下:
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Main {
public static void main(String[] args) {
LocalDate today = LocalDate.of(2022, 7, 1);
LocalDate finishDate = today.plusDays(253);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
String formattedDate = finishDate.format(formatter);
System.out.println("工程竣工日期为:" + formattedDate);
}
}
输出结果为:
工程竣工日期为:2023年03月11日
原文地址: https://www.cveoy.top/t/topic/bXKM 著作权归作者所有。请勿转载和采集!