本文主要是介绍根据传入时间推算半月时间段,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
主方法:
/*** 推算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;}
}
这篇关于根据传入时间推算半月时间段的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!