java string转LocalDateTime
时间: 2024-05-14 12:10:31 浏览: 156
可以使用Java 8中的DateTimeFormatter类将字符串转换为LocalDateTime对象。以下是一个示例代码:
```java
String str = "2022-12-31 23:59:59";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse(str, formatter);
```
其中,`str`是要转换的字符串,`formatter`是日期时间格式化器,使用`ofPattern()`方法指定日期时间格式。最后,调用`parse()`方法将字符串解析为LocalDateTime对象。
相关问题
java String转Localdatetime
可以使用Java 8中的DateTimeFormatter将String转换为LocalDateTime,如下所示:
String dateStr = "2021-07-20 12:30:00";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse(dateStr, formatter);
java String转LocalDateTime
可以使用Java 8中的DateTimeFormatter类来将String转换为LocalDateTime。具体代码如下:
```java
String str = "2021-08-31T10:15:30";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse(str, formatter);
```
其中,`str`是要转换的字符串,`formatter`是指定的格式,`dateTime`是转换后得到的LocalDateTime对象。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)