get方式时间格式统一

/ 2024-12-11

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
public class FlexibleDateTimeConverter implements Converter<String, String> {

  1. @Override
  2. public String convert(String source) {
  3. if (source == null || source.trim().isEmpty()) return null;
  4. String text = source.trim();
  5. if (text.matches("^\\d{4}-\\d{2}$")) {
  6. text += "-01 00:00:00";
  7. } else if (text.matches("^\\d{4}-\\d{2}-\\d{2}$")) {
  8. text += " 00:00:00";
  9. } else if (text.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}$")) {
  10. text += ":00:00";
  11. } else if (text.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}$")) {
  12. text += ":00";
  13. }
  14. return text;
  15. }

}


转载请注明作者和出处,并添加本页链接。
原文链接: //pongpongkai.top/62

皖ICP备2025092356号-1 | 沪公网安备31011202021249号