双十一马上到了,若客户没有对订单进行签收,系统n天后进行自动确认
import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;
public class ShoppingOnline {
public static void main(String[] args) throws ParseException {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String startime=sc.nextLine();//用字符串形式输入日期
int n=sc.nextInt();//输入确认时间期限
DateTimeFormatter sdf=DateTimeFormatter.ofPattern(“yyyy-MM-dd HH:mm:ss”);//设置时间日期格式
LocalDateTime starday=LocalDateTime.parse(startime,sdf);//将字符串设置为时间
LocalDateTime endtime=starday.plusDays(n);//添加天数
System.out.print(endtime.format(sdf));//输出
}
}
注:HH:mm:ss 为时,分,秒
当时为H,24小时进制
当时为h,12小时进制
利用LocalDateTime输出
最新推荐文章于 2025-04-01 17:05:07 发布