Timestamp2DateConverter.java 901 Bytes
package cn.fw.hestia.server.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.util.Date;

/**
 * @author : kurisu
 * @className : Timestamp2DateConverter
 * @description : {@link String} to {@link Date}
 * @date: 2021-01-19 10:04
 */
@Component
@ConfigurationPropertiesBinding
public class Timestamp2DateConverter implements Converter<String, Date> {
    @Override
    @Nullable
    public Date convert(@Nullable final String value) {
        if (StringUtils.isNotBlank(value) && NumberUtils.isDigits(value)) {
            return new Date(new Long(value));
        }
        return null;
    }
}