LocalDateTime 当前时间转yyyy-MM-dd HH:mm:ss字符串
时间: 2023-11-30 16:43:21 浏览: 100
yyyyMMddHHmmss 字符串 转DateTime
以下是将当前时间转换为yyyy-MM-dd HH:mm:ss字符串的Java代码:
```java
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Main {
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = now.format(formatter);
System.out.println("Current time: " + formattedDateTime);
}
}
```
输出结果为:
```
Current time: 2022-08-23 16:30:45
```
阅读全文