/** * @param nowDate 要比较的时间 * @param startDate 开始时间 * @param endDate 结束时间 * @return Y 在时间段内,N不在时间段内 * @throws Exception */ public static String panduanTimeSection(String nowDate, String startDate, String endDate) throws Exception{ SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); try{ Date now = format.parse(nowDate); Date start = format.parse(startDate); Date end = format.parse(endDate); //使用Date的方法转为毫秒比较大小 if(now.getTime() >= start.getTime()){ //当前时间大于等于开始时间 if(now.getTime() <= end.getTime()){ //当前时间小于等于结束时间 return "Y"; }else { return "N"; } }else { return "N"; } } catch (Exception e){ System.out.println(e.getMessage()); return "N"; } }