public static void main(String[] args) throws ParseException {
Scanner x = new Scanner(System.in);
System.out.println("请输入商品的生产日期: (yyyy-MM-dd)");
String a = x.nextLine();
System.out.println("请输入保质期: (天)");
int b = x.nextInt();
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date d1 = f.parse(a);
c.setTime(d1);
c.add(Calendar.DAY_OF_YEAR, b);
Date d2 = new Date();
String i = f.format(d2);
System.out.println("今天的日期为: " + i);
Calendar d = Calendar.getInstance();
if (d2.after(c.getTime())) {
System.out.println("商品已经过期");
} else {
if (c.get(Calendar.YEAR) == d.get(Calendar.YEAR)) {
int p = c.get(Calendar.DAY_OF_YEAR) - d.get(Calendar.DAY_OF_YEAR);
System.out.println("商品还有" + p + "天过期");
} else {
int p = c.get(Calendar.DAY_OF_YEAR) - d.get(Calendar.DAY_OF_YEAR)
+ 365 * (c.get(Calendar.YEAR) - d.get(Calendar.YEAR));
System.out.println("商品还有" + p + "天过期");
}
}
}