欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

判断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;
	}