返回两个时间段内的季度

Posted prader6

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了返回两个时间段内的季度相关的知识,希望对你有一定的参考价值。

参考文章:https://www.cnblogs.com/caoyingjielxq/p/9426972.html

public static Date parse(String string, String  patern){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(patern);
        try {
            Date parse = simpleDateFormat.parse(string);
            return parse;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
 
    
/**
* 返回两个时间段内,季度的字符串
* @param minDate
* @param maxDate
* @return
*/
     public static List<String> getMonthBetweenDates(String minDate, String maxDate){
        ArrayList<String> result = new ArrayList<String>();
        //HashSet<String> strings = new HashSet<>();
        HashMap<String, Integer> map = new HashMap<>();

        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();
        min.setTime(parse(minDate,"yyyy-MM-dd"));
        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);
        max.setTime(parse(maxDate,"yyyy-MM-dd"));
        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);

        Calendar curr = min;
        int i = 1;
        while (curr.before(max)) {
            //result.add(format(curr.getTime(),"yyyy-MM-dd"));
            String season1 = getSeason1(curr.getTime());
            map.put(season1, i);
            curr.add(Calendar.MONTH, 1);
            i++;
        }
        ArrayList<Map.Entry<String, Integer>> entries = new ArrayList<>(map.entrySet());
        Collections.sort(entries, new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o1.getValue().compareTo(o2.getValue());
            }
        });
        for (Map.Entry<String, Integer> entry : entries){
            result.add(entry.getKey());
        }
        return result;
    }

    /**
     *
     * 1 第一季度 2 第二季度 3 第三季度 4 第四季度
     *
     * @param date
     * @return
     */
    public static String getSeason1(Date date) {
        int season = 0;
        String seasonString = "";
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int month = c.get(Calendar.MONTH);
        int year = c.get(Calendar.YEAR);
        switch (month) {
            case Calendar.JANUARY:
            case Calendar.FEBRUARY:
            case Calendar.MARCH:
                season = 1;
                seasonString = year + "年第一季度";
                break;
            case Calendar.APRIL:
            case Calendar.MAY:
            case Calendar.JUNE:
                season = 2;
                seasonString = year + "年第二季度";
                break;
            case Calendar.JULY:
            case Calendar.AUGUST:
            case Calendar.SEPTEMBER:
                season = 3;
                seasonString = year + "年第三季度";
                break;
            case Calendar.OCTOBER:
            case Calendar.NOVEMBER:
            case Calendar.DECEMBER:
                season = 4;
                seasonString = year + "年第四季度";
                break;
            default:
                break;
        }
        return seasonString;
    }

 

------------恢复内容结束------------

以上是关于返回两个时间段内的季度的主要内容,如果未能解决你的问题,请参考以下文章

如何在嵌套片段内的两个子片段之间进行通信

转到不在底部导航视图内的片段并返回后,底部导航视图不起作用

片段内的LinearLayout总是在顶部留下空白

带有片段的 NavigationDrawer 内的 Android TabLayout

使用从循环内的代码片段中提取的函数避免代码冗余/计算开销

在通知单击时将项目添加到片段内的 recyclerview