org.onetwo.common.convert.ToDateConvertor Maven / Gradle / Ivy
package org.onetwo.common.convert;
import java.util.Date;
import org.onetwo.common.date.DateUtils;
public class ToDateConvertor extends AbstractTypeConvert {
protected ToDateConvertor() {
super(new Date(0));
}
@Override
public Date doConvert(Object value, Class> componentType) {
// if(value==null)
// return null;
Class> vtype = value.getClass();
Date date = null;
if(Date.class.isAssignableFrom(vtype)){
date = new Date(((Date)value).getTime());
}else if(CharSequence.class.isAssignableFrom(vtype)){
date = DateUtils.parse(value.toString());
}else if(Number.class.isAssignableFrom(vtype)){
date = new Date(((Number)value).longValue());
}
return date;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy