org.lockss.laaws.rs.config.LocalDateTimeConverter Maven / Gradle / Ivy
The newest version!
package org.lockss.laaws.rs.config;
import org.springframework.core.convert.converter.Converter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
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);
}
}