判断Date是否在一个时间范围内
程序员文章站
2024-03-07 13:08:39
...
private static boolean inAuspiciousPeriod(String startDate, String endDate) {
int startYear = Integer.parseInt(startDate.split("-")[0]);
int startMonth = Integer.parseInt(startDate.split("-")[1]);
int startDay = Integer.parseInt(startDate.split("-")[2]);
int endYear = Integer.parseInt(endDate.split("-")[0]);
int endMonth = Integer.parseInt(endDate.split("-")[1]);
int endDay = Integer.parseInt(endDate.split("-")[2]);
Calendar start = Calendar.getInstance(Locale.CHINESE);
Calendar current = Calendar.getInstance(Locale.CHINESE);
Calendar end = Calendar.getInstance(Locale.CHINESE);
start.set(startYear, startMonth-1, startDay);//月份减1
current.setTime(new Date());
end.set(endYear, endMonth-1, endDay);//月份减1
return start.compareTo(current)<=0 && end.compareTo(current)>=0;
}
上一篇: android 一些工具类汇总
下一篇: 【腾讯2017秋招笔试编程题】编码