LocalDateTime获取本月月初
时间: 2023-10-15 15:26:49 浏览: 155
要获取本月月初,可以使用以下方法:
1. 使用LocalDate类:
LocalDate now = LocalDate.now();
LocalDate firstDay = now.with(TemporalAdjusters.firstDayOfMonth());
2. 使用LocalDateTime类:
LocalDateTime date = LocalDateTime.now();
LocalDateTime firstDay = date.with(TemporalAdjusters.firstDayOfMonth());
以上两种方法都可以获取当前月份的第一天,可以根据个人需求选择使用哪种方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [LocalDate、LocalTime、LocalDateTime介绍](https://blog.csdn.net/weixin_44084024/article/details/126362860)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [Java使用LocalDate获取某个月的第一天和最后一天日期](https://blog.csdn.net/m0_67402564/article/details/125128139)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文