輸出指定日期區間內的所有天、周、月

hutool獲取指定時間周幾


?

@Slf4j
public class DateWeekUtil {public static List<String> getDateWeek(String startDateString, String endDateString, List<Integer> codeList) {List<String> dateInfoList = new ArrayList<>();List<Integer> valueList = WeekTypeEnum.getValueByCode(codeList);List<String> dateStrList = getDatesBetween(startDateString, endDateString);for (String dateStr : dateStrList) {Date date = parseYyyyMMdd(dateStr);Integer weekDay = DateUtil.dayOfWeek(date);//獲得指定日期是星期幾,1表示周日,2表示周一if (valueList.contains(weekDay)) {dateInfoList.add(dateStr);}}return dateInfoList;}/*** 輸入輸出yyyy-MM-dd格式** @param startDateString* @param endDateString* @return*/public static List<String> getDatesBetween(String startDateString, String endDateString) {List<DateTime> datesBetween = DateUtil.rangeToList(DateUtil.parseDate(startDateString), DateUtil.parseDate(endDateString), DateField.DAY_OF_MONTH);return datesBetween.stream().map(p -> DateUtil.format(p, DatePattern.NORM_DATE_PATTERN)).collect(Collectors.toList());}/*** 輸入輸出yyyy-MM-dd格式** @param startDateString* @param endDateString* @return*/public static List<DateItemVo> getDateItemVoBetween(String startDateString, String endDateString) {List<DateTime> datesBetween = DateUtil.rangeToList(DateUtil.parseDate(startDateString), DateUtil.parseDate(endDateString), DateField.DAY_OF_MONTH);List<String> dateInfoList = datesBetween.stream().map(p -> DateUtil.format(p, DatePattern.NORM_DATE_PATTERN)).collect(Collectors.toList());List<DateItemVo> dateItemVoList = new ArrayList<>();for (String dateInfo : dateInfoList) {String[] split = dateInfo.split("-");int year = Integer.parseInt(split[0]);int mounth = Integer.parseInt(split[1]);int day = Integer.parseInt(split[2]);Date dateTime = parseYyyyMMdd(dateInfo);Integer weekDayValue = DateUtil.dayOfWeek(dateTime);//獲得指定日期是星期幾,1表示周日,2表示周一DateItemVo dateItemVo = new DateItemVo();dateItemVo.setTimeInfo(dateInfo);dateItemVo.setTimeInfoShort(mounth + "." + day);dateItemVo.setWeekCode(WeekTypeEnum.getWeekTypeEnumByValue(weekDayValue).getCode());dateItemVo.setWeekName(WeekTypeEnum.getWeekTypeEnumByValue(weekDayValue).getName());dateItemVo.setWeekValue(weekDayValue);dateItemVoList.add(dateItemVo);}return dateItemVoList;}public static DateItemVo getToday(Date todayDate) {String todayDateString = DateUtil.format(todayDate, "yyyy-MM-dd");String[] split = todayDateString.split("-");int year = Integer.parseInt(split[0]);int mounth = Integer.parseInt(split[1]);int day = Integer.parseInt(split[2]);Integer weekDayValue = DateUtil.dayOfWeek(todayDate);//獲得指定日期是星期幾,1表示周日,2表示周一DateItemVo dateItemVo = new DateItemVo();dateItemVo.setWeekCode(WeekTypeEnum.getWeekTypeEnumByValue(weekDayValue).getCode());dateItemVo.setWeekName(WeekTypeEnum.getWeekTypeEnumByValue(weekDayValue).getName());dateItemVo.setWeekValue(weekDayValue);dateItemVo.setTimeInfo(todayDateString);dateItemVo.setTimeInfoShort(mounth + "." + day);return dateItemVo;}public static void main(String[] args) {List<Integer> integers = Arrays.asList(1, 2, 6, 7);List<String> datesBetweenList = getDateWeek("2024-02-27", "2024-04-03", integers);List<DateItemVo> dateItemVoBetween = DateWeekUtil.getDateItemVoBetween("2024-02-27", "2024-04-03");DateItemVo today = DateWeekUtil.getToday(new Date());System.out.println();}/*** 日期格式化** @param date yyyy-MM-dd* @return*/public static Date parseYyyyMMdd(String date) {if (StringUtils.isBlank(date)) {return null;}try {return new SimpleDateFormat("yyyy-MM-dd").parse(date);} catch (ParseException e) {e.printStackTrace();throw new RuntimeException(e);}}}

package com.unicom.attendance.base.enums;import java.util.*;
import java.util.stream.Collectors;/*** @Copyright: Unicom (Zhejiang) Industrial Internet Co. <br/>* @Desc: <br/>* @ProjectName: park-hztljb-api <br/>* @Date: 2023/1/16 15:45 <br/>* @Author: March*/
public enum WeekTypeEnum {/***  1按日期選擇   2按周選擇*/WEEK1(1, "周一",2),WEEK2(2, "周二",3),WEEK3(3, "周三",4),WEEK4(4, "周四",5),WEEK5(5, "周五",6),WEEK6(6, "周六",7),WEEK7(7, "周日",1);WeekTypeEnum(Integer code, String name,Integer value) {this.code = code;this.name = name;this.value = value;}private Integer code;// 1周一  2周二  3周三  4周四  5周五  6周六  7周日private String name;private Integer value;//hutool定義的   (1=星期日,2=星期一...7=星期六)// int i1 = DateUtil.dayOfWeek(parse1);//獲得指定日期是星期幾,1表示周日,2表示周一public Integer getCode() {return this.code;}public Integer getValue() {return value;}public String getName() {return this.name;}public static WeekTypeEnum getWeekTypeEnumByCode(Integer codeInfo) {for(WeekTypeEnum weekTypeEnum: values()){if(weekTypeEnum.getCode().equals(codeInfo)){return weekTypeEnum;}}return null;}public static WeekTypeEnum getWeekTypeEnumByValue(Integer valueInfo) {for(WeekTypeEnum weekTypeEnum: values()){if(weekTypeEnum.getValue().equals(valueInfo)){return weekTypeEnum;}}return null;}public static List<Integer> getValueByCode(List<Integer> codeInfoList) {List<WeekTypeEnum> weekTypeEnumList = new ArrayList<>();List<Integer> valueList = new ArrayList<>();for(WeekTypeEnum weekTypeEnum: values()){for(Integer codeInfo:codeInfoList){if(weekTypeEnum.getCode().equals(codeInfo)){weekTypeEnumList.add(weekTypeEnum);}}}valueList= weekTypeEnumList.stream().map(WeekTypeEnum::getValue).collect(Collectors.toList());return valueList;}public static void main(String[] args) {WeekTypeEnum weekTypeEnum1 = getWeekTypeEnumByCode(1);WeekTypeEnum weekTypeEnum3 = getWeekTypeEnumByCode(3);WeekTypeEnum weekTypeEnum7 = getWeekTypeEnumByCode(7);List<Integer> integers = Arrays.asList(1, 3, 6, 7);List<Integer> valueByCode = getValueByCode(integers);System.out.println();}}

輸出指定日期區間內的所有天、周、月_hutool獲取次月的天數并把每一天輸出-CSDN博客

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/11175.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/11175.shtml
英文地址,請注明出處:http://en.pswp.cn/web/11175.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

工作隨機:linux 掛載LVM管理模式的磁盤

文章目錄 前言一、創建一個分區二、創建PV三、創建VG四、創建LV五、格式化并掛載目錄 前言 在數據庫管理中&#xff0c;常有比較頭疼的問題&#xff0c;就是一段時間發展后我的磁盤空間不夠了&#xff0c;想要擴容原有的目錄很是頭疼&#xff0c;那么LVM管理的優勢就體現出來了…

JAVA學習-練習試用Java實現改寫字符串

問題&#xff1a; 鍵盤錄入一個字符串&#xff0c;將字符串中的大寫改成小寫&#xff0c;小寫改成大寫&#xff0c;數字改成。例如heLLO123,輸出后為HEllo** 解答思路&#xff1a; import java.util.Scanner;public class StringConversion {public static void main(String…

單元測試之JUnit5知識點總結及代碼示例

單元測試是軟件開發過程中的一種驗證手段&#xff0c;它針對最小的可測試部分&#xff08;通常是函數或方法&#xff09;進行檢查和驗證。其實單元測試還是挺重要的&#xff0c;不過國內很多公司的項目其實并沒有做好單元測試&#xff0c;或者根本就沒做單元測試&#xff0c;原…

英語復習之英語形近詞總結(四)

英語形近詞總結復習第四部分&#xff1a; 單詞 釋義例句 genuine 英 /?d?enju?n/ 美 /?d?enju?n/ adj.真實的&#xff0c;真正的&#xff1b;誠懇的 1.Only genuine refugees can apply for asylum. 只有真正的難民才能申請政治避難。 《牛津詞典》 2.This isnt a genui…

C++筆試強訓day19

目錄 1.小易的升級之路 2.禮物的最大價值 3.對稱之美 1.小易的升級之路 鏈接 模擬就行&#xff0c;唯一可能是難點得就是gcd&#xff08;最大公約數&#xff09; #include <iostream> using namespace std; #define int long long const int N 1e5 10; int arr[N];…

兒童懸吊訓練系統如何進行制動肌的動力訓練

兒童懸吊訓練系統進行制動肌的動力訓練&#xff0c;可以按照以下步驟進行&#xff1a; 評估&#xff1a;首先&#xff0c;治療師需要對兒童的制動肌進行評估&#xff0c;確定其穩定性和力量水平&#xff0c;從而制定合適的訓練計劃。 選擇訓練方式&#xff1a;根據評估結果&am…

利用IP地址查詢解決被“薅羊毛”的方法

在互聯網時代&#xff0c;隨著各種網絡詐騙手段的不斷更新和演變&#xff0c;“薅羊毛”成為了一種常見的網絡犯罪行為。其中&#xff0c;利用查詢IP地址進行欺詐活動已經成為一種普遍的手段。當個人或組織的IP地址被不法分子查詢后&#xff0c;可能會面臨虛假注冊、盜取個人信…

Python中的絕對路徑與相對路徑詳解

對路徑與相對路徑 Python中的絕對路徑與相對路徑詳解什么是路徑&#xff1f;絕對路徑優點&#xff1a;缺點&#xff1a;示例&#xff1a; 相對路徑優點&#xff1a;缺點&#xff1a;示例&#xff1a; Python中如何使用**重點內容**&#xff1a;**在Python中&#xff0c;建議使用…

AVL Cruise與Simulink聯合仿真(通過MATLAB DLL方式)

最近畢業設計需要用到AVL Cruise與Simulink進行聯合仿真&#xff0c;分析汽車模型的經濟性。下面介紹一下我所知的AVL Cruise與Simulink聯合仿真的幾種方式&#xff0c;它們各自的優缺點&#xff0c;以及DLL方式聯合仿真的具體配置過程。我這里用的MATLAB軟件版本是2021a&#…

有邊數限制的最短路

文章目錄 題目 有邊數限制的最短路算法分析1、問題&#xff1a;為什么Dijkstra不能使用在含負權的圖中&#xff1f;dijkstra詳細步驟2、什么是bellman - ford算法&#xff1f;3、bellman - ford算法的具體步驟4、在下面代碼中&#xff0c;是否能到達n號點的判斷中需要進行if(di…

水準網間接平差

目錄 一、原理概述二、案例分析三、代碼實現 一、原理概述 間接平差的函數模型和隨機模型為&#xff1a; L ^ B X ^ d D σ 0 2 Q σ 0 2 P ? 1 \hat{L}B\hat{X}d\\ D\sigma_0^2Q\sigma_0^2P^{-1} L^BX^dDσ02?Qσ02?P?1 誤差方程為&#xff1a; V B x ^ ? l VB\ha…

信息系統項目管理師0104:詳細可行性研究(7項目立項管理—7.2項目可行性研究—7.2.3詳細可行性研究)

點擊查看專欄目錄 文章目錄 7.2.3詳細可行性研究1.詳細可行性研究的依據2.詳細可行性研究的原則3.詳細可行性研究的方法4.詳細可行性研究的內容5.詳細可行性研究報告記憶要點總結7.2.3詳細可行性研究 詳細可行性研究是在項目決策前對與項目有關的技術、經濟、

智慧公廁:打造智能、安全、舒適的公共廁所新時代

隨著智慧城市建設的不斷推進&#xff0c;公共設施的智能化也已成為一種必然趨勢。在這一背景下&#xff0c;智慧公廁作為城市管理的一個重要方面&#xff0c;正逐漸走進人們的視野。通過對所在轄區內所有公共廁所的全域感知、全網協同、全業務融合以及全場景智慧的賦能&#xf…

如何訓練一個大模型:LoRA篇

目錄 寫在前面 一、LoRA算法原理 1.設計思想 2.具體實現 二、peft庫 三、完整的訓練代碼 四、總結 寫在前面 現在有很多開源的大模型&#xff0c;他們一般都是通用的&#xff0c;這就意味著這些開源大模型在特定任務上可能力不從心。為了適應我們的下游任務&#xff0c;…

使用Python構建一個簡單的圖書管理系統

Python是一種強大而靈活的編程語言&#xff0c;它可以用于構建各種類型的應用程序&#xff0c;包括圖書管理系統。在這篇文章中&#xff0c;我們將學習如何使用Python和一些常見的庫來創建一個簡單的圖書管理系統。 1. 設計數據庫模型 首先&#xff0c;我們需要設計數據庫模型…

【退役之重學 Java】初步認識 AQS

一、AQS 是什么 Abstract Queued Synchronizer &#xff0c;翻譯過來就是“抽象的排好隊的同步器”。 AQS 是一個用來構建鎖和同步器的框架。是用來構建鎖或者其他同步器組件的重量級基礎框架及整個JUC體系的基石&#xff0c;通過內置的FIFO隊列來完成線程獲取資源的排隊工作&…

centos7時間同步教程

針對問題&#xff1a;在我們使用虛擬機配置好centos7后&#xff0c;發現服務器時間和當前時間對不上 通過命令查看時間不同步 date 或者 date -R修改/etc/sysconfig/clock文件如下內容&#xff0c;保存 vi /etc/sysconfig/clockZONE“Asia/Shanghai” UTCtrue ARCfalse重寫/e…

251 基于matlab的動態粒子群算法

基于matlab的動態粒子群算法。普通粒子群算法無法感知外界環境的變化&#xff0c;在外界環境發生改變時無法實時進行響應&#xff0c;因而缺乏動態環境尋優能力。在普通粒子群算法基本上通過增加敏感粒子得到一種動態粒子群算法&#xff0c;該算法通過實時計算敏感粒子的適應度…

2024年第七屆可再生能源與電力工程國際會議(REPE 2024)即將召開!

2024年第七屆可再生能源與電力工程國際會議&#xff08;REPE 2024&#xff09;將于2024年9月25-27日在中國北京召開, 由清華大學主辦。REPE 2024將匯聚國內外知名專家學者通過主旨報告、分組討論和互動交流等形式&#xff0c;分享最新的研究成果、技術進展和應用案例&#xff0…

【教程向】從零開始創建瀏覽器插件(二)深入理解 Chrome 擴展的 manifest.json 配置文件

第二步&#xff1a;深入理解 Chrome 擴展的 manifest.json 配置文件 上一次我們已經著手完成了一個自己的瀏覽器插件&#xff0c;鏈接在這里&#xff1a;我是鏈接 在本篇博客中&#xff0c;我們將更詳細地探討 Chrome 擴展中的 manifest.json 文件。這個文件是每個瀏覽器擴展…