- //获得本季度
- public String getThisSeasonTime(int month){
- int array[][] = {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
- int season = 1;
- if(month>=1&&month<=3){
- season = 1;
- }
- if(month>=4&&month<=6){
- season = 2;
- }
- if(month>=7&&month<=9){
- season = 3;
- }
- if(month>=10&&month<=12){
- season = 4;
- }
- int start_month = array[season-1][0];
- int end_month = array[season-1][2];
- Date date = new Date();
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");//可以方便地修改日期格式
- String years = dateFormat.format(date);
- int years_value = Integer.parseInt(years);
- int start_days =1;//years+"-"+String.valueOf(start_month)+"-1";//getLastDayOfMonth(years_value,start_month);
- int end_days = getLastDayOfMonth(years_value,end_month);
- String seasonDate = years_value+"-"+start_month+"-"+start_days+";"+years_value+"-"+end_month+"-"+end_days;
- return seasonDate;
- }
- /**
- * 获取某年某月的最后一天
- * @param year 年
- * @param month 月
- * @return 最后一天
- */
- private int getLastDayOfMonth(int year, int month) {
- if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8
- || month == 10 || month == 12) {
- return 31;
- }
- if (month == 4 || month == 6 || month == 9 || month == 11) {
- return 30;
- }
- if (month == 2) {
- if (isLeapYear(year)) {
- return 29;
- } else {
- return 28;
- }
- }
- return 0;
- }
- /**
- * 是否闰年
- * @param year 年
- * @return
- */
- public boolean isLeapYear(int year) {
- return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
- }
- }