欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

12.17

程序员文章站 2022-07-15 14:18:36
...

package Text9;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Text2 {

	public static void main(String[] args) throws ParseException {
		System.out.println("按下格式请输入:yyyy-MM-dd");
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		System.out.println("请输入保质期:");
		int S = sc.nextInt();
		
		SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
		Date date = f.parse(s);
		
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.add(Calendar.DAY_OF_MONTH,S);
		String x = f.format(c.getTime());
		
		System.out.println(x);
		Date d = c.getTime();
			
		SimpleDateFormat f1 = new SimpleDateFormat("yyyy-MM-dd");
		Calendar c1 = Calendar.getInstance();
		String y = f1.format(new Date());
		Date d1 = c1.getTime();
		System.out.println("当前日期:");
		System.out.println(y);
		
		 boolean b = d1.before(d); 
		 if(b){
			
		int t = 30-(d1.getDate()-d.getDate());
		System.out.println("没过期,剩余天数:"+t);
		 }else{
			 System.out.println("过期");
			  }
		 
	}

}

上一篇: 12.17

下一篇: (模板)字符串hash