根据传入时间推算半月时间段

2023-10-12 06:38

本文主要是介绍根据传入时间推算半月时间段,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

主方法:

/*** 推算4个  半月时间段** @param condition* @return*/public EvErpPFDemandQC getDateEvTimeRangeQC(EvErpPFDemandQC condition) {Calendar calendar = Calendar.getInstance();calendar.setTime(condition.getQueryTime());int day = calendar.get(Calendar.DAY_OF_MONTH);//获取当月、下月、下下月时间组EvErpPFDemandQC dateOne = getDateFirstAndLast(condition.getQueryTime(), 0);EvErpPFDemandQC dateTwo = getDateFirstAndLast(condition.getQueryTime(), 1);EvErpPFDemandQC dateThree = getDateFirstAndLast(condition.getQueryTime(), 2);if (day <= 15) {setCondition(condition, dateOne.getFirst(), dateOne.getFifteen(), dateOne.getSixteen(), dateOne.getLast(), dateTwo.getFirst(), dateTwo.getFifteen(), dateTwo.getSixteen(), dateTwo.getLast());} else {setCondition(condition, dateOne.getSixteen(), dateOne.getLast(), dateTwo.getFirst(), dateTwo.getFifteen(), dateTwo.getSixteen(), dateTwo.getLast(), dateThree.getFirst(), dateThree.getFifteen());}return condition;}

 封装:

private void setCondition(EvErpPFDemandQC condition, Date startTimeOne, Date endTimeOne, Date startTimeTwo, Date endTimeTwo, Date startTimeThree, Date endTimeThree, Date startTimeFour, Date endTimeFour) {condition.setStartTimeOne(startTimeOne);condition.setEndTimeOne(endTimeOne);condition.setStartTimeTwo(startTimeTwo);condition.setEndTimeTwo(endTimeTwo);condition.setStartTimeThree(startTimeThree);condition.setEndTimeThree(endTimeThree);condition.setStartTimeFour(startTimeFour);condition.setEndTimeFour(endTimeFour);}

获取具体时间时钟格式值:

 /*** 获取月份开始/结束/月中日期(精确到yyyy-MM-dd HH:mm:ss)** @param queryTime* @param i* @return*/public EvErpPFDemandQC getDateFirstAndLast(Date queryTime, Integer i) {EvErpPFDemandQC condition=new EvErpPFDemandQC();Calendar calendar = Calendar.getInstance();calendar.setTime(queryTime);calendar.add(Calendar.MONTH, i);//月份int year = calendar.get(Calendar.YEAR);int month = calendar.get(Calendar.MONDAY);int maximum = calendar.getActualMaximum(Calendar.DATE);//第一天calendar.set(year, month, 1,00, 00, 00);//月份第一天condition.setFirst(calendar.getTime());//第十六天calendar.set(year, month, 16, 00, 00, 00);condition.setSixteen(calendar.getTime());//第十五天calendar.set(year, month, 15, 23, 59, 59);//最后一刻condition.setFifteen(calendar.getTime());//最后一天calendar.set(year, month, maximum, 23, 59, 59);//月份最后一天condition.setLast(calendar.getTime());return condition;}

 实体:

package cn.lionbridgecapital.ev.erp.condition.everpproplexquartz;import cn.lionbridgecapital.ev.core.pojo.QueryCondition;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;import java.util.Date;/*** @author wangguangle* @date 2019/11/15 20:05*/
@ApiModel(value = "[XXXXXX数据查询参数")
@JsonIgnoreProperties(ignoreUnknown = true)
public class EvErpPFDemandQC extends QueryCondition {@ApiModelProperty(value = "选择时间 yyyy-MM-dd HH:mm:ss - yyyy-MM-dd HH:mm:ss")private Date queryTime;/*** 月份第一天*/@JsonIgnoreprivate Date startTimeOne;/*** 第一段结束时间*/@JsonIgnoreprivate Date endTimeOne;/*** 第二段开始时间*/@JsonIgnoreprivate Date startTimeTwo;/*** 第二段结束时间*/@JsonIgnoreprivate Date endTimeTwo;/*** 第三段开始时间*/@JsonIgnoreprivate Date startTimeThree;/*** 第三段结束时间*/@JsonIgnoreprivate Date endTimeThree;/*** 第四段开始时间*/@JsonIgnoreprivate Date startTimeFour;/*** 第四段结束时间*/@JsonIgnoreprivate Date endTimeFour;/*** 月份第一天*/@JsonIgnoreprivate Date first;/*** 月份第15天*/@JsonIgnoreprivate Date fifteen;/*** 月份第16天*/@JsonIgnoreprivate Date sixteen;/*** 月份最后一天*/@JsonIgnoreprivate Date last;public EvErpPFDemandQC() {}public Date getQueryTime() {return queryTime;}public void setQueryTime(Date queryTime) {this.queryTime = queryTime;}public Date getStartTimeOne() {return startTimeOne;}public void setStartTimeOne(Date startTimeOne) {this.startTimeOne = startTimeOne;}public Date getEndTimeOne() {return endTimeOne;}public void setEndTimeOne(Date endTimeOne) {this.endTimeOne = endTimeOne;}public Date getStartTimeTwo() {return startTimeTwo;}public void setStartTimeTwo(Date startTimeTwo) {this.startTimeTwo = startTimeTwo;}public Date getEndTimeTwo() {return endTimeTwo;}public void setEndTimeTwo(Date endTimeTwo) {this.endTimeTwo = endTimeTwo;}public Date getStartTimeThree() {return startTimeThree;}public void setStartTimeThree(Date startTimeThree) {this.startTimeThree = startTimeThree;}public Date getEndTimeThree() {return endTimeThree;}public void setEndTimeThree(Date endTimeThree) {this.endTimeThree = endTimeThree;}public Date getStartTimeFour() {return startTimeFour;}public void setStartTimeFour(Date startTimeFour) {this.startTimeFour = startTimeFour;}public Date getEndTimeFour() {return endTimeFour;}public void setEndTimeFour(Date endTimeFour) {this.endTimeFour = endTimeFour;}public Date getFirst() {return first;}public void setFirst(Date first) {this.first = first;}public Date getFifteen() {return fifteen;}public void setFifteen(Date fifteen) {this.fifteen = fifteen;}public Date getSixteen() {return sixteen;}public void setSixteen(Date sixteen) {this.sixteen = sixteen;}public Date getLast() {return last;}public void setLast(Date last) {this.last = last;}
}

 

这篇关于根据传入时间推算半月时间段的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/193972

相关文章

Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码

《Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码》:本文主要介绍Java中日期时间转换的多种方法,包括将Date转换为LocalD... 目录一、Date转LocalDateTime二、Date转LocalDate三、LocalDateTim

golang获取当前时间、时间戳和时间字符串及它们之间的相互转换方法

《golang获取当前时间、时间戳和时间字符串及它们之间的相互转换方法》:本文主要介绍golang获取当前时间、时间戳和时间字符串及它们之间的相互转换,本文通过实例代码给大家介绍的非常详细,感兴趣... 目录1、获取当前时间2、获取当前时间戳3、获取当前时间的字符串格式4、它们之间的相互转化上篇文章给大家介

Feign Client超时时间设置不生效的解决方法

《FeignClient超时时间设置不生效的解决方法》这篇文章主要为大家详细介绍了FeignClient超时时间设置不生效的原因与解决方法,具有一定的的参考价值,希望对大家有一定的帮助... 在使用Feign Client时,可以通过两种方式来设置超时时间:1.针对整个Feign Client设置超时时间

springboot+dubbo实现时间轮算法

《springboot+dubbo实现时间轮算法》时间轮是一种高效利用线程资源进行批量化调度的算法,本文主要介绍了springboot+dubbo实现时间轮算法,文中通过示例代码介绍的非常详细,对大家... 目录前言一、参数说明二、具体实现1、HashedwheelTimer2、createWheel3、n

Java实现时间与字符串互相转换详解

《Java实现时间与字符串互相转换详解》这篇文章主要为大家详细介绍了Java中实现时间与字符串互相转换的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、日期格式化为字符串(一)使用预定义格式(二)自定义格式二、字符串解析为日期(一)解析ISO格式字符串(二)解析自定义

Java时间轮调度算法的代码实现

《Java时间轮调度算法的代码实现》时间轮是一种高效的定时调度算法,主要用于管理延时任务或周期性任务,它通过一个环形数组(时间轮)和指针来实现,将大量定时任务分摊到固定的时间槽中,极大地降低了时间复杂... 目录1、简述2、时间轮的原理3. 时间轮的实现步骤3.1 定义时间槽3.2 定义时间轮3.3 使用时

Python如何获取域名的SSL证书信息和到期时间

《Python如何获取域名的SSL证书信息和到期时间》在当今互联网时代,SSL证书的重要性不言而喻,它不仅为用户提供了安全的连接,还能提高网站的搜索引擎排名,那我们怎么才能通过Python获取域名的S... 目录了解SSL证书的基本概念使用python库来抓取SSL证书信息安装必要的库编写获取SSL证书信息

MySQL 日期时间格式化函数 DATE_FORMAT() 的使用示例详解

《MySQL日期时间格式化函数DATE_FORMAT()的使用示例详解》`DATE_FORMAT()`是MySQL中用于格式化日期时间的函数,本文详细介绍了其语法、格式化字符串的含义以及常见日期... 目录一、DATE_FORMAT()语法二、格式化字符串详解三、常见日期时间格式组合四、业务场景五、总结一、

Java实现检查多个时间段是否有重合

《Java实现检查多个时间段是否有重合》这篇文章主要为大家详细介绍了如何使用Java实现检查多个时间段是否有重合,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录流程概述步骤详解China编程步骤1:定义时间段类步骤2:添加时间段步骤3:检查时间段是否有重合步骤4:输出结果示例代码结语作

Java判断多个时间段是否重合的方法小结

《Java判断多个时间段是否重合的方法小结》这篇文章主要为大家详细介绍了Java中判断多个时间段是否重合的方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录判断多个时间段是否有间隔判断时间段集合是否与某时间段重合判断多个时间段是否有间隔实体类内容public class D