当前位置:网站首页>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 ";
}
}
}
边栏推荐
- 项目总结--2(Jsoup的基本使用)
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- Pytorch dataloader implements minibatch (incomplete)
- phpstudy设置项目可以由局域网的其他电脑可以访问
- Simple handwritten ORM framework
- Kubernetes notes (VIII) kubernetes security
- tabbar的设置
- Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
- Svn branch management
- Core principles and source code analysis of disruptor
猜你喜欢
深入解析kubernetes controller-runtime
Kubernetes notes (VII) kuberetes scheduling
23 design models
技术管理进阶——你了解成长的全貌吗?
Oauth2.0 - user defined mode authorization - SMS verification code login
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
理解 期望(均值/估计值)和方差
Oauth2.0 - using JWT to replace token and JWT content enhancement
Bernoulli distribution, binomial distribution and Poisson distribution, and the relationship between maximum likelihood (incomplete)
表达式的动态解析和计算,Flee用起来真香
随机推荐
[set theory] equivalence relation (concept of equivalence relation | examples of equivalence relation | equivalence relation and closure)
Clickhouse learning notes (I): Clickhouse installation, data type, table engine, SQL operation
Kubernetes notes (VII) kuberetes scheduling
88. Merge two ordered arrays
Migrate data from Amazon aurora to tidb
理解 期望(均值/估计值)和方差
Convolution operation in convolution neural network CNN
1. Sum of two numbers
Disruptor learning notes: basic use, core concepts and principles
有意思的鼠标指针交互探究
Naive Bayes in machine learning
1. Somme des deux nombres
从小数据量 MySQL 迁移数据到 TiDB
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Kubernetes notes (III) controller
Apifix installation
pytorch DataLoader实现miniBatch(未完成)
CKA certification notes - CKA certification experience post
Why should there be a firewall? This time xiaowai has something to say!!!
tabbar的设置