package com.liying.tiger.test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date; public class Test {
public static void main(String[] args) throws ParseException {
String format = "HH:mm:ss";
Date nowTime = new SimpleDateFormat(format).parse("09:27:00");
Date startTime = new SimpleDateFormat(format).parse("09:27:00");
Date endTime = new SimpleDateFormat(format).parse("09:27:59");
System.out.println(isEffectiveDate(nowTime, startTime, endTime));
} /**
* 判断当前时间是否在[startTime, endTime]区间,注意时间格式要一致
*
* @param nowTime 当前时间
* @param startTime 开始时间
* @param endTime 结束时间
* @return
* @author jqlin
*/
public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
if (nowTime.getTime() == startTime.getTime()
|| nowTime.getTime() == endTime.getTime()) {
return true;
} Calendar date = Calendar.getInstance();
date.setTime(nowTime); Calendar begin = Calendar.getInstance();
begin.setTime(startTime); Calendar end = Calendar.getInstance();
end.setTime(endTime); if (date.after(begin) && date.before(end)) {
return true;
} else {
return false;
}
}
}

JAVA8:

//构造时间  00:20:55
LocalTime time1 = LocalTime.of(8,20,55);
LocalTime time3 = LocalTime.of(15,20,55);
LocalTime time4 = LocalTime.of(18,10,55); if (time1.isBefore(time3) && time4.isAfter(time3)){
System.out.println("在时间区间之内!");
}

JAVA判断时间是否在时间区间内的更多相关文章

  1. Uva LA 3177 - Beijing Guards 贪心,特例分析,判断器+二分,记录区间内状态数目来染色 难度: 3

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  2. Python3基础 if elif 示例 判断一个数在哪个区间内

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  3. c# 判断当前时间是否在 工作日时间段内

    #region //获取当前周几 private string _strWorkingDayAM = "08:30";//工作时间上午08:00 private string _s ...

  4. SQL Server 判定时间是否在某个时间区间内

    * FROM sys.objects WHERE name=N'uF_IsRange_Date' AND [type]='FN') DROP FUNCTION uF_IsRange_Date GO S ...

  5. java获取前一天时间SimpleDateFormat,java判断某个时间段

    java获取前一天时间SimpleDateFormat SimpleDateFormat predf = new SimpleDateFormat("yyyy-MM-dd"); D ...

  6. .net判断当前时间是否在工作时间段内

    整理代码,判断当前时间是否在配置的工作时间段内,代码如下: public static bool getTimeSpan(string _strWorkingDayAM, string _strWor ...

  7. iOS判断当前时间是否处于某个时间段内

    /** * 判断当前时间是否处于某个时间段内 * * @param startTime 开始时间 * @param expireTime 结束时间 */ - (BOOL)validateWithSta ...

  8. java Joda-Time 对日期、时间操作

    任何企业应用程序都需要处理时间问题.应用程序需要知道当前的时间点和下一个时间点,有时它们还必须计算这两个时间点之间的路径.使用 JDK 完成这项任务将非常痛苦和繁琐.现在来看看 Joda Time,一 ...

  9. Java Calendar.set 方法设置时间的问题

    因项目需要,需要遍历一年中的其中几个月,获得每个月的用户数量.  变量有:开始时间--startDate,结束时间--endDate. 逻辑很简单:获取到开始时间的月份和结束时间的月份,然后得到月份差 ...

  10. js 日期比较大小,js判断日期是否在区间内,js判断时间段是否在另外一个时间段内

    /** * 日期解析,字符串转日期 * @param dateString 可以为2017-02-16,2017/02/16,2017.02.16 * @returns {Date} 返回对应的日期对 ...

随机推荐

  1. SQL Server 数据库修改后不允许保存

    打开 工具 - > 选项 -> 设计器,确认[阻止保存要求重新创建表的更改]项是否选中,如果选中,取消即可.

  2. 3元购买微信小程序解决方案一个月

    一.登录微信公众平台https://mp.weixin.qq.com/ 二.点击立即注册.注意:这里不要用微信公众号登录,小程序账号和微信公众号是不同的. 三.在注册页面点击小程序板块. 四.进入小程 ...

  3. yjh_study_command

    1.show current user in oralce ansower:show user 2.search  name of table  in current user model. answ ...

  4. spring-4.3.16+xfire-spring-1.2.6版本升级

    最近爆了个spring的漏洞,然后公司整体要求升级spring到最新版本,然后搞四了一大批猿人. spring-4.*的最新版本是4.3.16(稳定版) xfire-spring-1.2.6(最新版- ...

  5. 初识Git与Github

    学习和使用Git和Github的确是一件很有意义的事,通过使用Git和Github,可以让我们很方便地管理自己的各种文件,还可以帮助一名程序员更好地用于代码管理.而对于一名软件技术人员,建立自己的Gi ...

  6. 【HHHOJ】ZJOI2019模拟赛(十六)4.07 解题报告

    点此进入比赛 得分: \(100+100+100=300\) 排名: \(Rank\ 1\) \(Rating\): \(+13\)(\(\frac18Rated\)) 备注: 这场比赛全是做过的原题 ...

  7. BZOJ2648/2716:SJY摆棋子/[Violet]天使玩偶(K-D Tree)

    Description 这天,SJY显得无聊.在家自己玩.在一个棋盘上,有N个黑色棋子.他每次要么放到棋盘上一个黑色棋子,要么放上一个白色棋子,如果是白色棋子,他会找出距离这个白色棋子最近的黑色棋子. ...

  8. SQL Server的Bug

    SQL 语句如下: SELECT * FROM Production.Product WHERE ProductNumber IN(SELECT ProductNumber FROM HumanRes ...

  9. 论文翻译:XNOR-Net: ImageNet Classification Using BinaryConvolutional Neural Networks

    目录 Abstract 1 Introduction 2 Related Work 3 Binary Convolutional Neural Network 3.1 Binary-Weight-Ne ...

  10. 【luogu P1402 酒店之王】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1402 菜 #include <queue> #include <cstdio> #i ...