get方式时间格式统一
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
@Component
public class FlexibleDateTimeConverter implements Converter<String, String> {
@Override
public String convert(String source) {
if (source == null || source.trim().isEmpty()) return null;
String text = source.trim();
if (text.matches("^\\d{4}-\\d{2}$")) {
text += "-01 00:00:00";
} else if (text.matches("^\\d{4}-\\d{2}-\\d{2}$")) {
text += " 00:00:00";
} else if (text.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}$")) {
text += ":00:00";
} else if (text.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}$")) {
text += ":00";
}
return text;
}
}
转载请注明作者和出处,并添加本页链接。
原文链接:
//pongpongkai.top/62