posts - 0,  comments - 0,  trackbacks - 0
1. 返回当前月的天数
1calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
2. 返回两个日期之间的每一天
 1import java.text.SimpleDateFormat;   
 2import java.util.Date;   
 3  
 4public class Demo {   
 5    public static void main(String[] args) throws Exception {   
 6        Date start = new SimpleDateFormat("yyy-MM-dd").parse("2008-08-29");   
 7        Date end = new SimpleDateFormat("yyy-MM-dd").parse("2008-09-02");   
 8           
 9        start = new Date(start.getTime() + 86400000);   
10           
11        while(start.getTime() <= end.getTime()){   
12            System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(start));   
13            start = new Date(start.getTime() + 86400000);   
14        }
   
15           
16    }
   
17}
  
18
3. 返回某月的天数
1public int getDaysInMonth(int year, int mon) {   
2  java.util.GregorianCalendar date = new java.util.GregorianCalendar(   
3    year, mon - 11);   
4  return (date.getActualMaximum(Calendar.DATE));   
5 }
 

 1class   test        
 2  {      
 3          public   static   void   main(String[]   args)        
 4          {      
 5                  int   i   =   getMaxDays(1997,5);      
 6          }
      
 7          public   int   getMaxDays(int   year,int   month)        
 8          {      
 9                  switch(month)      
10                  {      
11                          case   1:      
12                          case   3:      
13                          case   5:      
14                          case   7:      
15                          case   8:      
16                          case   10:      
17                          case   12:      
18                              return   31;      
19                              break;      
20                          case   4:      
21                          case   6:      
22                          case   9:      
23                          case   11:      
24                              return   30;      
25                              break;      
26                          default:        
27                                  if((year%4==0   &&   year%100!=0)   ||   (year%400==0))      
28                                          return   29;      
29                                  else      
30                                          return   28;      
31                                  break;      
32                  }
      
33          }
      
34  }
   
posted on 2009-05-28 00:38 王晗 阅读(45) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 
<2025年7月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

留言簿

文章档案

搜索

  •  

最新评论