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

cn.featherfly.conversion.string.basic.LocalTimeConvertor Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version

package cn.featherfly.conversion.string.basic;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

import cn.featherfly.common.lang.GenericType;
import cn.featherfly.common.lang.StringUtils;
import cn.featherfly.conversion.ConversionException;

/**
 * 

* LocalTime类转换器 *

* * @author 钟冀 */ public class LocalTimeConvertor extends AbstractBasicConvertor> { private static final String DATE_TIME_FORMAT = "HH:mm:ss"; private static final DateTimeFormatter DATE_TIME_PATTERN = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); /** */ public LocalTimeConvertor() { } /** * {@inheritDoc} */ @Override protected String doToString(LocalTime value, GenericType genericType) { if (value != null) { return value.format(DATE_TIME_PATTERN); } return ""; } /** * {@inheritDoc} */ @Override protected LocalTime doToObject(String value, GenericType genericType) { if (StringUtils.isNotBlank(value)) { value = value.trim(); try { return LocalTime.parse(value, DATE_TIME_PATTERN); } catch (Exception e) { throw new ConversionException("#convert_failed_with_type", new Object[] { value, DATE_TIME_FORMAT, getSourceType().getName() }); } } return null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy