java,android:判断当前时间是否属于该时间段
2020年12月04日
| 萬仟网IT编程
| 我要评论
自己写的一方法 /** * judge the current time is on the time, for example: current is 11:00, startTimeStringFormat=10:00,endTimeStringFormat==12:00,you will get true * * @param startTimeStringFormat String:"HH:mm" you must follow the format
自己写的一方法
/**
* judge the current time is on the time, for example: current is 11:00, startTimeStringFormat=10:00,endTimeStringFormat==12:00,you will get true
*
* @param startTimeStringFormat String:"HH:mm" you must follow the format
* @param endTimeStringFormat String:"HH:mm" you must follow the format
* @return boolean: if the the current time on the range
* @throws Exception : simpleDateFormat.parse maybe null, simpleDateFormat.parse mayby exception
*/
public static boolean currentTimebelongTheRange(String startTimeStringFormat, String endTimeStringFormat) throws Exception {
String dateFormatString = "HH:mm";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatString);
//first get now time calendar
String nowTimeFormat = simpleDateFormat.format(new Date());
Date nowTimeData = simpleDateFormat.parse(nowTimeFormat);
Calendar nowTimeCalendar = Calendar.getInstance();
nowTimeCalendar.setTime(Objects.requireNonNull(nowTimeData));
//second get start time calendar
Date startTimeData = simpleDateFormat.parse(startTimeStringFormat);
Calendar startTimeCalendar = Calendar.getInstance();
startTimeCalendar.setTime(Objects.requireNonNull(startTimeData));
//third get end time calendar
Date endTimeData = simpleDateFormat.parse(endTimeStringFormat);
Calendar endTimeCalendar = Calendar.getInstance();
endTimeCalendar.setTime(Objects.requireNonNull(endTimeData));
return nowTimeCalendar.after(startTimeCalendar) && nowTimeCalendar.before(endTimeCalendar);
}
本文地址:https://blog.csdn.net/qq_36017059/article/details/110631471
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
相关文章:
COOKIE与SESSION 1,基本概念 cookie机制采用的是在客户端保持状态的方案,当你在浏览网站的时候,cookie是一个文本信息,会帮你...
public class SwitchCase { public static void main(String[] args) { System....
1.新建一个springboot工程2.需要导入mybatis和mybatis-plus的依赖文件
这一篇目的就是在于网页爬虫的实现,对数据的获取,以便分析。
目录:
1、爬虫原理
2、本地文件数据提取及分析
3、单...
其实很多读者都在关注微服务层是如何设计的,其中包括微服务架构、规则流程、定义标准,其实本篇文章不想过多的重复介绍...
java 实现计数排序和桶排序实例代码
目录
比较和非比较的区别
常见的快速排序、归并排序、堆排序、冒泡排序等属于比较排序。在...
本文实例讲述了java简单数组排序(冒泡法)。分享给大家供大家参考,具体如下:
import java.util.scan...
public static String entityToUrlParam(T t){ ...
1,前言有关@ComponentScan的Filter属性的记录2,Filter@ComponentScan中还...
网友评论
验证码: