需求:如字符串2019-7-1 9:6:5转成2019-07-01 09:06:05

java8实现如下:

public static String getStartDate(String startDate) {
DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern("yyyy-M-d H:m:s");
DateTimeFormatter outputFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return LocalDateTime.parse(startDate, inputFormat).format(outputFormat);
}
04-07 13:44