天天看點

java比較兩個日期的天數_JAVA比較兩個日期的內插補點天數

package com.anxin.ssk.cache;

import java.text.SimpleDateFormat;

import java.util.Date;

import org.apache.commons.lang.time.DateUtils;

public class C {

public static void main(String[] args) {

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

Date today = new Date();

System.out.println(sdf.format(today));

Date anotherDate = DateUtils.addDays(today, 21);

System.out.println(sdf.format(anotherDate));

System.out.println((int) ((anotherDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24)));

}

}

// 2014-01-17

// 2014-02-07

// 21