BeanUtils的自己定義的日期轉換器
阿新 • • 發佈:2019-02-06
package cn.servlet; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.commons.beanutils.Converter; public class myconver implements Converter { //把頁面上傳進來的String 轉化為 date public Object convert(Class type, Object value) { System.out.println(type); System.out.println(value); String s = (String) value; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date=null; try { date = sdf.parse(s); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return date; } }