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

JAVA比较两个日期的差值天数

程序员文章站 2022-06-29 12:08:18
...
package com.anxin.ssk.cache;

import java.text.SimpleDateFormat;
import java.util.Date;

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

/**
 * @author: (le.qiao)
 * @e-mail: qiaolevip@gmail.com
 * @myblog: <a href="http://qiaolevip.iteye.com">http://qiaolevip.iteye.com</a>
 * @date: 2014-1-17
 * 
 */
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