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";
分类:
Java基础
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了