判断某时间是否处于时间区域内

/**
* @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";
        }
    }

 

posted @ 2018-11-01 10:36  闻长歌而知雅意  阅读(350)  评论(0)    收藏  举报