求2个日期之间的差,显示X年X月X日

比如 2014-7-11 减去2014-6 -11,显示结果为 0030

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
	        
	        long s=sdf.parse("2015-05-16").getTime()-sdf.parse("2011-05-16").getTime();
	         
	        System.out.println(sdf.format(new Date(s)));//1971-04-15 可以减去1970-01-01
	         
	        Calendar c=Calendar.getInstance();
	        c.setTime(new Date(s));
	        System.out.println(c.get(Calendar.YEAR)-1970) ;
	        System.out.println(c.get(Calendar.MONTH)) ;
	        System.out.println(c.get(Calendar.DAY_OF_MONTH)-1) ;


你可能感兴趣的:(类)