com.cloud.platform.web.dozeConverter.StringToLocalDateConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloud-web-spring-boot-starter Show documentation
Show all versions of cloud-web-spring-boot-starter Show documentation
project for cloud-web-spring-boot-starter
The newest version!
package com.cloud.platform.web.dozeConverter;
import com.github.dozermapper.core.DozerConverter;
import org.apache.commons.lang3.StringUtils;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* @description:
* @author: zhou shuai
* @date: 2022/4/2 18:44
* @version: v1
*/
public class StringToLocalDateConverter extends DozerConverter {
public StringToLocalDateConverter() {
super(String.class, LocalDate.class);
}
public LocalDate convertTo(String source, LocalDate target) {
if (StringUtils.isNotBlank(source)) {
return LocalDate.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
return null;
}
public String convertFrom(LocalDate source, String target) {
if (source != null) {
return source.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy