使用LocalDateTime查询时间数据带T如何去掉
要去掉LocalDateTime查询时间数据中的T,可以使用DateTimeFormatter的ofPattern方法来自定义日期时间格式。以下是一个示例代码:
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);
}
}
这段代码将当前的LocalDateTime对象格式化为"yyyy-MM-dd HH:mm:ss"的字符串格式,并打印输出。其中,"T"被替换成了空格" "。你可以根据需要调整DateTimeFormatter的模式来满足你的要求
原文地址: https://www.cveoy.top/t/topic/iEVc 著作权归作者所有。请勿转载和采集!