获取各种常用时间方法(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. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值