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";
复制代码

 




posted @   三国梦回  阅读(6804)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示