计算某日期开始x天的日期(女票问题100天,521,1000天纪念日是哪一天?)

往往记不住各种纪念日,恋爱多天天呐 ,结婚纪念日.......受不了数学是正常人教的了,发挥程序狗的优势搞了一个小方法。

 1 /**返回开始日期起止多少天的日期
 2      * @param startDate
 3      * @param num
 4      * @return
 5      */
 6     public Date makeFutureDaysBeforeTodays(Date startDate,int num){
 7         Date endDay = new Date();
 8         Calendar c = Calendar.getInstance();
 9         c.setTime(startDate);
10         endDay= c.getTime();
11         while (num >= 1) {
12             endDay.setDate(endDay.getDate() + 1);//把结果日往前推一天
13             num--;
14             System.out.println("循环内返回的日期是:"+instance.df.format(endDay));
15         }
16         return endDay;
17     }
18     public static void main(String[] args) throws Exception {
19         Date d1 = new Date("2014/04/26");
20         Date d2 = new Date();
21         WorkDateUtil instance = WorkDateUtil.getInstance();
22         //workTime = instance.getCalWorkTimes(d1, d2,3);
23         d2 = instance.makeFutureDaysBeforeTodays(d1, 521);
24         System.out.println("返回的日期是:"+instance.df.format(d2));
25 
26     }

 

posted @ 2015-07-27 09:12  张大佳  阅读(1531)  评论(2编辑  收藏  举报