• jodatime 时间比较


    public ArrayList<CalcPeriod> getCalcPeriods() {
            DateTime now = DateTime.now();
            DateTime.Property year = now.year();
    
            DateTimeFormatter yyyyMMdd = DateTimeFormat.forPattern("yyyyMMdd");
            DateTime season1 = DateTime.parse(year.get() + Constant.SEASON1,yyyyMMdd);
            DateTime season2 = DateTime.parse(year.get() + Constant.SEASON2,yyyyMMdd);
            DateTime season3 = DateTime.parse(year.get() + Constant.SEASON3,yyyyMMdd);
            DateTime season4 = DateTime.parse(year.get() + Constant.SEASON4,yyyyMMdd);
            //2.1 今年
            ArrayList<CalcPeriod> currentYearList = new ArrayList<>();
            if (now.isBefore(season1)){
    
            }else if (now.isAfter(season1) && now.isBefore(season2)){
                currentYearList.add(new CalcPeriod(year.get(),"1"));
            }else if (now.isAfter(season2) && now.isBefore(season3)) {
                currentYearList.add(new CalcPeriod(year.get(), "2"));
            }else if (now.isAfter(season3) && now.isBefore(season4)) {
                currentYearList.add(new CalcPeriod(year.get(), "3"));
            }
            //2.2 去年
            ArrayList<CalcPeriod> beforeCurrentYearList = new ArrayList<>();
            for (int i = 2012; i <= year.get() - 1; i++){
                for (int j = 1; j <= 4; j++){
                    beforeCurrentYearList.add(new CalcPeriod(i, String.valueOf(j)));
                }
            }
            ArrayList<CalcPeriod> totalList = new ArrayList<>();
            totalList.addAll(currentYearList);
            totalList.addAll(beforeCurrentYearList);
            return totalList;
        }
    
    public class CalcPeriod
    {
        private int year;
        private String period;
    
        public CalcPeriod(int year, String period) {
            this.year = year;
            this.period = period;
        }
    
        public CalcPeriod() {
        }
    
        public int getYear()
        {
            return this.year;
        }
    
        public void setYear(int year) {
            this.year = year;
        }
    
    }
    
    
        public static final String SEASON1 = "0331";
        public static final String SEASON2 = "0630";
        public static final String SEASON3 = "0930";
        public static final String SEASON4 = "1231";
  • 相关阅读:
    linux 服务器---FastDFS分布式文件服务器配置
    JFinal getModel方法(从页面表单中获取Model对象)+数据库存储问题
    实现Callable接口。带返回值的线程
    Spring 自动化装配Bean
    Spring--基于代理类ProxyFactoryBean的AOP实现
    Jfinal中的validator理解/详解
    Jfinal中的文件上传
    HotSpot学习(二):虚拟机的启动过程源码解析
    HotSpot学习(一):编译、启动与调试
    Netty的对象池
  • 原文地址:https://www.cnblogs.com/grey-wolf/p/7009641.html
Copyright © 2020-2023  润新知