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

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

相关文章

go中的时间处理过程

《go中的时间处理过程》:本文主要介绍go中的时间处理过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1 获取当前时间2 获取当前时间戳3 获取当前时间的字符串格式4 相互转化4.1 时间戳转时间字符串 (int64 > string)4.2 时间字符串转时间

Golang如何对cron进行二次封装实现指定时间执行定时任务

《Golang如何对cron进行二次封装实现指定时间执行定时任务》:本文主要介绍Golang如何对cron进行二次封装实现指定时间执行定时任务问题,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录背景cron库下载代码示例【1】结构体定义【2】定时任务开启【3】使用示例【4】控制台输出总结背景

C++ 函数 strftime 和时间格式示例详解

《C++函数strftime和时间格式示例详解》strftime是C/C++标准库中用于格式化日期和时间的函数,定义在ctime头文件中,它将tm结构体中的时间信息转换为指定格式的字符串,是处理... 目录C++ 函数 strftipythonme 详解一、函数原型二、功能描述三、格式字符串说明四、返回值五

从基础到进阶详解Pandas时间数据处理指南

《从基础到进阶详解Pandas时间数据处理指南》Pandas构建了完整的时间数据处理生态,核心由四个基础类构成,Timestamp,DatetimeIndex,Period和Timedelta,下面我... 目录1. 时间数据类型与基础操作1.1 核心时间对象体系1.2 时间数据生成技巧2. 时间索引与数据

利用Python实现时间序列动量策略

《利用Python实现时间序列动量策略》时间序列动量策略作为量化交易领域中最为持久且被深入研究的策略类型之一,其核心理念相对简明:对于显示上升趋势的资产建立多头头寸,对于呈现下降趋势的资产建立空头头寸... 目录引言传统策略面临的风险管理挑战波动率调整机制:实现风险标准化策略实施的技术细节波动率调整的战略价

Python日期和时间完全指南与实战

《Python日期和时间完全指南与实战》在软件开发领域,‌日期时间处理‌是贯穿系统设计全生命周期的重要基础能力,本文将深入解析Python日期时间的‌七大核心模块‌,通过‌企业级代码案例‌揭示最佳实践... 目录一、背景与核心价值二、核心模块详解与实战2.1 datetime模块四剑客2.2 时区处理黄金法

macOS Sequoia 15.5 发布: 改进邮件和屏幕使用时间功能

《macOSSequoia15.5发布:改进邮件和屏幕使用时间功能》经过常规Beta测试后,新的macOSSequoia15.5现已公开发布,但重要的新功能将被保留到WWDC和... MACOS Sequoia 15.5 正式发布!本次更新为 Mac 用户带来了一系列功能强化、错误修复和安全性提升,进一步增

Pandas进行周期与时间戳转换的方法

《Pandas进行周期与时间戳转换的方法》本教程将深入讲解如何在pandas中使用to_period()和to_timestamp()方法,完成时间戳与周期之间的转换,并结合实际应用场景展示这些方法的... 目录to_period() 时间戳转周期基本操作应用示例to_timestamp() 周期转时间戳基

JavaScript时间戳与时间的转化常用方法

《JavaScript时间戳与时间的转化常用方法》在JavaScript中,时间戳(Timestamp)通常指Unix时间戳,即从1970年1月1日00:00:00UTC到某个时间点经过的毫秒数,下面... 目录1. 获取当前时间戳2. 时间戳 → 时间对象3. 时间戳php → 格式化字符串4. 时间字符

Java controller接口出入参时间序列化转换操作方法(两种)

《Javacontroller接口出入参时间序列化转换操作方法(两种)》:本文主要介绍Javacontroller接口出入参时间序列化转换操作方法,本文给大家列举两种简单方法,感兴趣的朋友一起看... 目录方式一、使用注解方式二、统一配置场景:在controller编写的接口,在前后端交互过程中一般都会涉及