LocalDateTime转换格式
时间: 2023-11-09 10:00:48 浏览: 99
时间格式转换
可以使用DateTimeFormatter类来转换LocalDateTime的格式。例如,将LocalDateTime转换为字符串:
```
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formatDateTime = now.format(formatter);
System.out.println(formatDateTime);
```
将字符串转换为LocalDateTime:
```
String dateTimeStr = "2022-01-01 12:00:00";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse(dateTimeStr, formatter);
System.out.println(dateTime);
```
阅读全文