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

handlebars.JavaSpring.LocalDateTimeConverter.mustache Maven / Gradle / Ivy

There is a newer version: 1.0.54
Show newest version
package {{configPackage}};

import org.springframework.core.convert.converter.Converter;
{{^isJava8or11}}
import org.threeten.bp.LocalDateTime;
import org.threeten.bp.format.DateTimeFormatter;
{{/isJava8or11}}
{{#isJava8or11}}
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
{{/isJava8or11}}

public class LocalDateTimeConverter implements Converter {
    private final DateTimeFormatter formatter;

    public LocalDateTimeConverter(String dateFormat) {
        this.formatter = DateTimeFormatter.ofPattern(dateFormat);
    }

    @Override
    public LocalDateTime convert(String source) {
        if(source == null || source.isEmpty()) {
            return null;
        }
        return LocalDateTime.parse(source, this.formatter);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy