[ACCEPTED]-Java BeanUtilsBean : Convert Date to String-apache-commons
Accepted answer
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);
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
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.