当前位置:网站首页>Judge whether the date time exceeds 31 days
Judge whether the date time exceeds 31 days
2022-07-03 06:13:00 【Muyu】
At the end of the project , It is necessary to judge whether students are overdue , exceed 31 Days are overdue , So the following method is used .
/** * Enter two times , One is the start time , The other is the end time * Compare the two , Judge whether it is more than 31 God * @param startTime * @param endTime * @return */
public boolean checkOverdue(String startTime ,String endTime){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
Date end = sdf.parse(endTime);
Date start = sdf.parse(startTime);
long day = 60*1000*60*24; // 1 God
if(end.getTime()-(day*31) > start.getTime()){
return true;
}else{
return false;
}
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
Count the overdue times , First, check the borrowing records ( Here is the specific implementation of business functions )
/** * according to sid Find out the student's borrowing record * Then judge the overdue according to the borrowing time and return time in the borrowing record * Overdue is divided into the following three situations * 1. Never borrowed a book , Not overdue * 2. Borrowed books but not returned * Take out the borrowing time , Then take out the current time , If not more than 31 God , Is not overdue * Take out the borrowing time , Then take out the current time , If exceeded 31 God , Then overdue * 3. Borrowed books and returned them * Calculate the borrowing time directly , If exceeded 31 God , Then overdue * @param sid * @return */
public String checkOverdueBySid(int sid){
int num=0;
// Here is to check the borrowing record first
List<Borrow> borrows = borrowMapper.queryBorrowBySid(sid);
if(borrows==null) {
return " No overdue records ";
}else{
for (Borrow borrow : borrows) {
if("".equals(borrow.getReturnTime())||borrow.getReturnTime()==null){
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String nowTime = sdf.format(date);
if(checkOverdue(borrow.getBorrowTime(),nowTime)){
num+=1;
}
}else{
if(checkOverdue(borrow.getBorrowTime(),borrow.getReturnTime())){
num+=1;
}
}
}
if(num==0){
return " No overdue records ";
}else{
return " Within the time limit "+num+" Time ";
}
}
}
边栏推荐
- 项目总结--04
- Merge and migrate data from small data volume, sub database and sub table Mysql to tidb
- Oauth2.0 - using JWT to replace token and JWT content enhancement
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- Nacos service installation
- 伯努利分布,二项分布和泊松分布以及最大似然之间的关系(未完成)
- Oauth2.0 - user defined mode authorization - SMS verification code login
- How to create and configure ZABBIX
- 輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
- Understand expectations (mean / estimate) and variances
猜你喜欢

Analysis of Clickhouse mergetree principle

表达式的动态解析和计算,Flee用起来真香

Oauth2.0 - user defined mode authorization - SMS verification code login

Redis cluster creation, capacity expansion and capacity reduction

Es remote cluster configuration and cross cluster search

pytorch DataLoader实现miniBatch(未完成)

深入解析kubernetes controller-runtime

Migrate data from Mysql to tidb from a small amount of data

輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷

Kubesphere - build Nacos cluster
随机推荐
Common interview questions
Virtual memory technology sharing
phpstudy设置项目可以由局域网的其他电脑可以访问
从小数据量分库分表 MySQL 合并迁移数据到 TiDB
Code generator - single table query crud - generator
项目总结--2(Jsoup的基本使用)
BeanDefinitionRegistryPostProcessor
Project summary --04
Some thoughts on machine learning
pytorch 搭建神经网络最简版
JMeter performance automation test
Simple handwritten ORM framework
Oauth2.0 - explanation of simplified mode, password mode and client mode
Cesium 点击获三维坐标(经纬度高程)
Kubernetes notes (VII) kuberetes scheduling
Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)
Cesium entity (entities) entity deletion method
SQL实现将多行记录合并成一行
Merge and migrate data from small data volume, sub database and sub table Mysql to tidb
Leetcode solution - 02 Add Two Numbers