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

org.onetwo.common.convert.ToDateConvertor Maven / Gradle / Ivy

There is a newer version: 4.7.2
Show newest version
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