首页 > 技术文章 > java 日期增加

bilaisheng 2016-06-13 17:25 原文

 1 import java.text.ParseException;
 2 import java.text.SimpleDateFormat;
 3 import java.util.Date;
 4 
 5 
 6 public class Test {
 7     
 8     public static void main(String[] args) throws ParseException {
 9         //以下从1号开始增加10天
10         SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
11         int i =0;
12         Date nextday=null;
13         String a=null;
14         while (i<10) {
15             if (i==0) {
16                  a = sdf.format(sdf.parse("2016-01-01").getTime()+0*24*60*60*1000);
17             }else{
18                 a = sdf.format(nextday.getTime()+1*24*60*60*1000);
19             }
20             
21             nextday = sdf.parse(a);
22             System.out.println(sdf.format(nextday));
23             i++;
24         }
25     }
26 
27 }

 

推荐阅读