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);
    }

    }

  • 相关阅读:
    策略模式c++【转】
    [转]C++设计模式:Builder模式
    c/c++ 笔试面试题
    堆排序
    冒泡,快速,和堆排序
    C++继承
    【转】林建:计算机专业学习浅谈
    (centos)linux下访问双系统windows7文件系统
    sprintf() in c
    System call in linux by C
  • 原文地址:https://www.cnblogs.com/523823-wu/p/9225185.html
Copyright © 2011-2022 走看看