在Java之中用Calendar方法,我们可以容易的实现日期相关的计算:
    public class TestDate {
   
    public static void main(String[] args) {
   
    DateFormat format = new SimpleDateFormat(“yyyy-MM-dd”);
   
    Date date1 = null, date2 = null;
   
    try {
   
    date1 = format.parse(“2010-10-01”);
   
    date2 = format.parse(“2011-10-02”);
   
    } catch (ParseException e) {
   
    e.printStackTrace();
   
    }
   
    long diff = date1.getTime() - date2.getTime();//计算两个日期之前相差的毫秒数
   
    long days = diff / (24 * 60 * 60 * 1000)http://www.cqywzx.com/;//除以1天的毫秒数,得到相差的天数
   
    System.out.println(“这两个日期之间的天数为: ” + days);
   
    }
   
    }