Java获取指定日期的月初和月末日子
生活随笔
收集整理的這篇文章主要介紹了
Java获取指定日期的月初和月末日子
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
實現代碼:
| /*** 獲取指定日期的月初和月末日子** @param day 日期20200202*/ public static Date[] getMonthStartEnd(Date day) {LocalDateTime now = day.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();LocalDateTime first = LocalDateTime.of(now.getYear(), now.getMonth(), 1, 0, 0, 0, 0);LocalDateTime last = LocalDateTime.of(first.with(TemporalAdjusters.lastDayOfMonth()).getYear(),first.with(TemporalAdjusters.lastDayOfMonth()).getMonth(),first.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth(), 23, 59, 59);return new Date[]{Date.from(first.atZone(ZoneId.systemDefault()).toInstant()), Date.from(last.atZone(ZoneId.systemDefault()).toInstant())}; } |
?
總結
以上是生活随笔為你收集整理的Java获取指定日期的月初和月末日子的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网络延迟造成插入多条重复数据
- 下一篇: spring boot中使用@Async