`
wanii3344
  • 浏览: 18545 次
  • 性别: Icon_minigender_1
  • 来自: 河南
社区版块
存档分类
最新评论

两个日期之间的日期

 
阅读更多
public   class   TestDate   {  

          public   TestDate() {  
          }  
          public   static   void   main(String[]   args)  {  
                  String   dateStart   =   "2004-02-27";  
                  String   dateEnd   =   "2004-03-02";  
   
                  SimpleDateFormat   sdfStart   =   new SimpleDateFormat("yyyy-MM-dd");  
                  SimpleDateFormat   sdfEnd   =   new   SimpleDateFormat("yyyy-MM-dd");  
                  try {  
                          sdfStart.parse(dateStart);  
                          Calendar   clStart   =   sdfStart.getCalendar();  
                          sdfEnd.parse(dateEnd);  
                          Calendar   clEnd   =   sdfEnd.getCalendar();  
                          while(true) {  
                                  if   (   clStart.before   (   clEnd   )   ||   clStart.equals(clEnd))  
                                  {  
                                          System.out.println(sdfStart.format(clStart.getTime()));  
                                          clStart.add   (   clStart.DAY_OF_MONTH   ,   1   )   ;  
                                          clStart.set(clStart.DAY_OF_MONTH,clStart.get(clStart.DAY_OF_MONTH));  
                                  }  
                                  else  
                                  {  
                                          break   ;  
                                  }  
                          }  
                  }  
                  catch   (   ParseException   ex   )  
                  {  
                          ex.printStackTrace();  
                  }  
   
          }  
   
  }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics