java 当前系统小时时间 是否在时间段内

    /**
     *
     * 当前系统时间 是否在时间段内
     * @return
     * @throws Exception
     */
    public static boolean isTimeRange(String sTime, String eTime) {
        SimpleDateFormat df = new SimpleDateFormat("HH:mm");
        Date now = null;
        Date begin = null;
        Date end = null;
        try {
            now = df.parse(df.format(new Date()));
            begin = df.parse(sTime);
            end = df.parse(eTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar nowTime = Calendar.getInstance();
        nowTime.setTime(now);
        Calendar beginTime = Calendar.getInstance();
        beginTime.setTime(begin);
        Calendar endTime = Calendar.getInstance();
        endTime.setTime(end);
        if (nowTime.before(endTime) && nowTime.after(beginTime)) {
            return true;
        } else {
            return false;
        }
    }

 

posted @ 2020-04-01 12:20  zhangheliang  阅读(107)  评论(0编辑  收藏