All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cloud.platform.web.dozeConverter.StringToLocalDateTimeConverter Maven / Gradle / Ivy

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