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
上一篇: struts标签判断日期是否过期