java8 根據年份和周數 獲取周一和周日日期


WeekFields weekFields= WeekFields.ISO;
LocalDate now = LocalDate.now();
//輸入你想要的年份和周數
LocalDate localDate = now.withYear(2021).with(weekFields.weekOfYear(),1);

//以周一為每周的第一天

//周一(第一天)
LocalDate localDate1 = localDate.with(weekFields.dayOfWeek(), 1L);
//周日(第七天)
LocalDate localDate7 = localDate.with(weekFields.dayOfWeek(), 7L);

//以周日為每周的第一天

//周日(第一天)
LocalDate localDate1 = localDate.with(
WeekFields.of(Locale.US).dayOfWeek(), 1L);

//周六(第七天)
LocalDate localDate7 = localDate.with(weekFields.dayOfWeek(), 6L);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM