[ACCEPTED]-Java BeanUtilsBean : Convert Date to String-apache-commons

Accepted answer
Score: 11

You need a SimpleDateFormat by which to parse the given 7 string according to a specified format. For 6 that you'd need to handle the conversion 5 manually - name the request parameter differently 4 and then set it manually.

But beanutils has 3 a conversion utility, so you can use it 2 instead (this code can be executed once 1 per application):

DateTimeConverter dtConverter = new DateConverter();
dtConverter.setPattern("<your custom date pattern here>");
ConvertUtils.register(dtConverter, Date.class);
Score: 4

Done using this method:

public Object populate(Object obj, HashMap<String, String[]> formData)
            throws IllegalAccessException, InvocationTargetException {
        ConvertUtils
                .register(new StringToDateConverter(), java.util.Date.class);
        BeanUtilsBean.getInstance().populate(obj, formData);
        return obj;
    }

0

More Related questions