zoukankan      html  css  js  c++  java
  • 判断某时间是否处于时间区域内

    /**
    * @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";
            }
        }
    往事如烟,余生有我.
  • 相关阅读:
    POJ 1511
    POJ 1125
    POJ 2240
    POJ 1459
    POJ 1274
    POJ 1789
    POJ 2485,1258
    POJ 1236
    POJ 1273
    Ruby on Rails 观后感
  • 原文地址:https://www.cnblogs.com/assistants/p/9887864.html
Copyright © 2011-2022 走看看