`
yanjie349957322
  • 浏览: 14010 次
  • 性别: Icon_minigender_1
  • 来自: 成都
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

获取各种常用时间方法(2)

阅读更多
  1.   //获得本季度   
  2.     public String getThisSeasonTime(int month){   
  3.         int array[][] = {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};   
  4.         int season = 1;   
  5.         if(month>=1&&month<=3){   
  6.             season = 1;   
  7.         }   
  8.         if(month>=4&&month<=6){   
  9.             season = 2;   
  10.         }   
  11.         if(month>=7&&month<=9){   
  12.             season = 3;   
  13.         }   
  14.         if(month>=10&&month<=12){   
  15.             season = 4;   
  16.         }   
  17.         int start_month = array[season-1][0];   
  18.         int end_month = array[season-1][2];   
  19.            
  20.         Date date = new Date();   
  21.         SimpleDateFormat   dateFormat   =   new   SimpleDateFormat("yyyy");//可以方便地修改日期格式      
  22.         String  years  = dateFormat.format(date);      
  23.         int years_value = Integer.parseInt(years);   
  24.            
  25.         int start_days =1;//years+"-"+String.valueOf(start_month)+"-1";//getLastDayOfMonth(years_value,start_month);   
  26.         int end_days = getLastDayOfMonth(years_value,end_month);   
  27.         String seasonDate = years_value+"-"+start_month+"-"+start_days+";"+years_value+"-"+end_month+"-"+end_days;   
  28.         return seasonDate;   
  29.            
  30.     }   
  31.        
  32.     /**  
  33.      * 获取某年某月的最后一天  
  34.      * @param year 年  
  35.      * @param month 月  
  36.      * @return 最后一天  
  37.      */  
  38.    private int getLastDayOfMonth(int year, int month) {   
  39.          if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8  
  40.                    || month == 10 || month == 12) {   
  41.                return 31;   
  42.          }   
  43.          if (month == 4 || month == 6 || month == 9 || month == 11) {   
  44.                return 30;   
  45.          }   
  46.          if (month == 2) {   
  47.                if (isLeapYear(year)) {   
  48.                    return 29;   
  49.                } else {   
  50.                    return 28;   
  51.                }   
  52.          }   
  53.          return 0;   
  54.    }   
  55.    /**  
  56.     * 是否闰年  
  57.     * @param year 年  
  58.     * @return   
  59.     */  
  60.   public boolean isLeapYear(int year) {   
  61.         return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);   
  62.   }   
  63. }  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics