zoukankan      html  css  js  c++  java
  • java 时间范围


    if(isInTime("00:00-18:00", sd.format(new Date()))) {
    return Result.checkMsgFail("不在登记范围之内!");
    }

    public boolean isInTime(String sourceTime, String curTime) {
    if (sourceTime == null || !sourceTime.contains("-") || !sourceTime.contains(":")) {
    throw new IllegalArgumentException("Illegal Argument arg:" + sourceTime);
    }
    if (curTime == null || !curTime.contains(":")) {
    throw new IllegalArgumentException("Illegal Argument arg:" + curTime);
    }
    String[] args = sourceTime.split("-");
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    try {
    long now = sdf.parse(curTime).getTime();
    long start = sdf.parse(args[0]).getTime();
    long end = sdf.parse(args[1]).getTime();
    if (args[1].equals("00:00")) {
    args[1] = "24:00";
    }
    if (end < start) {
    if (now >= end && now < start) {
    return false;
    } else {
    return true;
    }
    }
    else {
    if (now >= start && now < end) {
    return true;
    } else {
    return false;
    }
    }
    } catch (Exception e) {
    e.printStackTrace();
    throw new IllegalArgumentException("Illegal Argument arg:" + sourceTime);
    }

    }

  • 相关阅读:
    Java 运动模糊
    Efounds笔试
    Algorithms code
    Java 画图
    Java 笔记
    Java 对二值化图片识别连通域
    工厂模式
    数据库克隆
    SQL优化
    微信调起jssdk一闪而过
  • 原文地址:https://www.cnblogs.com/523823-wu/p/9225185.html
Copyright © 2011-2022 走看看