当前位置:网站首页>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 ";
}
}
}
边栏推荐
- YOLOV3学习笔记
- 多线程与高并发(7)——从ReentrantLock到AQS源码(两万字大章,一篇理解AQS)
- Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
- Cesium 点击获取模型表面经纬度高程坐标(三维坐标)
- 智牛股--03
- Simple solution of small up main lottery in station B
- Simple understanding of ThreadLocal
- tabbar的设置
- SVN分支管理
- Jedis source code analysis (I): jedis introduction, jedis module source code analysis
猜你喜欢

理解 期望(均值/估计值)和方差

Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow

Bernoulli distribution, binomial distribution and Poisson distribution, and the relationship between maximum likelihood (incomplete)

arcgis创建postgre企业级数据库

Core principles and source code analysis of disruptor

多线程与高并发(7)——从ReentrantLock到AQS源码(两万字大章,一篇理解AQS)

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

Simple understanding of ThreadLocal

Method of converting GPS coordinates to Baidu map coordinates

Zhiniu stock project -- 05
随机推荐
Cesium entity (entities) entity deletion method
88. 合并两个有序数组
Leetcode solution - 02 Add Two Numbers
Loss function in pytorch multi classification
About the difference between count (1), count (*), and count (column name)
Kubernetes notes (V) configuration management
Cesium 点击获三维坐标(经纬度高程)
Simple handwritten ORM framework
Beandefinitionregistrypostprocessor
Jedis source code analysis (I): jedis introduction, jedis module source code analysis
Skywalking8.7 source code analysis (I): agent startup process, agent configuration loading process, custom class loader agentclassloader, plug-in definition system, plug-in loading
深入解析kubernetes controller-runtime
Kubernetes notes (VIII) kubernetes security
Project summary --04
Es remote cluster configuration and cross cluster search
Kubesphere - build Nacos cluster
Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
1. 两数之和
Naive Bayes in machine learning
智牛股项目--05