LocalDateTime如何去掉T
时间: 2023-10-26 08:27:27 浏览: 103
您好!对于去掉 `LocalDateTime` 中的 "T",您可以使用 `DateTimeFormatter` 来格式化日期时间。以下是一个示例代码:
```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(formattedDateTime);
}
}
```
在这个示例中,我们使用了 `DateTimeFormatter` 的 `ofPattern` 方法来指定日期时间的格式。"yyyy-MM-dd HH:mm:ss" 表示年份、月份、日期、小时、分钟、秒钟的格式。`LocalDateTime` 的 `format` 方法将日期时间对象按照指定的格式转换为字符串,最后打印出来。此时,就不会包含 "T" 字符了。
希望能对您有所帮助!如有任何疑问,请随时提问。
阅读全文
相关推荐

















