/**
* 判断当前时间是否在[startTime, endTime]区间,注意时间格式要一致
*
* @param nowTime 当前时间
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
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;
}
}
/**
* 判断时间是否在[startTime, endTime]区间,注意时间格式要一致
* @param nowTime
* @param startTime
* @param endTime
* @return
*/
public static boolean isEffectiveDate(String nowTime, String startTime, String endTime,String dateFormat) {
DateFormat df = new SimpleDateFormat(dateFormat);
Date nowDate = null;
Date startDate = null;
Date endDate = null;
try {
nowDate = df.parse(nowTime);
startDate = df.parse(startTime);
endDate = df.parse(endTime);
} catch (ParseException e) {
e.printStackTrace();
}
if (nowDate.getTime() == startDate.getTime()
|| nowDate.getTime() == endDate.getTime()) {
return true;
}
Calendar date = Calendar.getInstance();
date.setTime(nowDate);
Calendar begin = Calendar.getInstance();
begin.setTime(startDate);
Calendar end = Calendar.getInstance();
end.setTime(endDate);
if (date.after(begin) && date.before(end)) {
return true;
} else {
return false;
}
}java判断date在某个区间 java判断时间区间
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
java条件判断题:判断这一天是当年的第几天
从键盘分别输入年、月、日,判断这一天是当年的第几天
System switch语句 条件判断 -
java判断时间是否在区间内 java 时间区间判断
java判断时间是否在区间内 java 时间区间判断
java 服务器 开发语言 处理方法 日期格式 -
【rabbitmq 高级特性】RabbitMQ 延迟队列全面解析
本文介绍了RabbitMQ中实现延迟队列的两种方式:TTL+死信队列组合和官方延迟插件。TTL+死信队列通过设置消息TTL和死信交换机
rabbitmq 分布式 代码实现 实现原理 延迟时间 -
Cucumber + Pytest(python)实现自动化(BDD)
摘要: 本文介绍了如何将BDD(行为驱动开发)与pytest+Python结合实现自动化测试。通过pytest-bdd插件,开发者可以使用Gherkin语法编写业务可读的测试用例,同时利用pytest的fixture、参数化等功能。文章详细说明了项目目录结构、Gherkin特性文件编写、步骤定义实现、PageObject模式应用以及测试运行与报告生成方法。这种组合兼具业务可读性和技术灵活性,支持丰富的测试报告和CI/CD集成,是现代化自动化测试的高效实践方案。(150字)
pytest python 自动化 Gherkin 运行测试
















