LocalDateTime获取年月日
时间: 2023-10-26 13:27:27 浏览: 104
要获取LocalDateTime的年月日,可以使用format方法和DateTimeFormatter类来进行格式化。具体的代码如下所示:
```
LocalDateTime localDateTime = LocalDateTime.now();
String formattedDate = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
System.out.println("当前日期为:" + formattedDate);
```
这段代码将会输出当前的年月日,格式为"yyyy-MM-dd",例如"2022-01-01"。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [LocalDateTime只获取年月日](https://blog.csdn.net/sinat_29774479/article/details/81483741)[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: 100%"]
[ .reference_list ]
阅读全文