判断当前时间是否在某多个时间段

来源:互联网 发布:演员 知乎 编辑:程序博客网 时间:2024/04/28 18:32
/*** 使用方法(传入时间间隔的字符串 如:10:00-14:52,16:30-20:59)*/@SuppressWarnings("deprecation")public static boolean timelag(String FORWARDPERIOD){Date now=new Date();ArrayList<Integer> timeTmp;for (String  gaptemp: FORWARDPERIOD.split(",")) {timeTmp=new ArrayList<Integer>();for (String tmp : gaptemp.split("-")) {for (String temp : tmp.split(":")) {timeTmp.add(Integer.parseInt(temp));}}if(timeTmp.get(0)<=(Integer) now.getHours()&&timeTmp.get(2)>=(Integer) now.getHours()){if((Integer) now.getHours()==timeTmp.get(0)){if(timeTmp.get(1)<(Integer) now.getMinutes()){return true;}}else if((Integer) now.getHours()==timeTmp.get(2)){if(timeTmp.get(3)>(Integer) now.getMinutes()){return true;}}else{return true;}}}return false;}



-----------------------------------程序员 闫帆原创---------------------------------------

转载请注明原创人信息  程序员 闫帆yanfanvip


原创粉丝点击