Timestamp2LocalDateConverter.java
943 Bytes
package cn.fw.valhalla.converter;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
/**
* create at 2020-10-19
*
* @author kurisu
*/
@Component
@ConfigurationPropertiesBinding
public class Timestamp2LocalDateConverter implements Converter<String, LocalDate> {
@Override
@Nullable
public LocalDate convert(@Nullable final String value) {
if (StringUtils.isNotBlank(value) && NumberUtils.isDigits(value)) {
return Instant.ofEpochMilli(NumberUtils.toLong(value)).atZone(ZoneId.systemDefault()).toLocalDate();
}
return null;
}
}