com.cloud.platform.web.dozeConverter.StringToLocalDateTimeConverter 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.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* @description:
* @author: zhou shuai
* @date: 2022/4/2 18:44
* @version: v1
*/
public class StringToLocalDateTimeConverter extends DozerConverter {
public StringToLocalDateTimeConverter() {
super(String.class, LocalDateTime.class);
}
public LocalDateTime convertTo(String source, LocalDateTime target) {
if (StringUtils.isNotBlank(source)) {
return LocalDateTime.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}
return null;
}
public String convertFrom(LocalDateTime source, String target) {
if (source != null) {
return source.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy