spring 日期格式

static {
		//注册日期字符到对象转换器
		Converter dateConverter = new Converter() {
			@Override
			public Object convert(Class type, Object value) {
				try {
					return DateUtil.DATE_FORMAT2().parse((java.lang.String) value);
				} catch (ParseException e) {
					throw new RuntimeException(e);
				}
			}
			@Override
			public java.lang.String toString() {
				return "date for yyyy-MM-dd";
			}
		};
		System.out.println(BeanUtilsBean.getInstance().getConvertUtils().lookup(Date.class));
		BeanUtilsBean.getInstance().getConvertUtils().register(dateConverter, Date.class);
		System.out.println("BeanUtilsBean.getInstance().getConvertUtils().lookup(Date.class):"+BeanUtilsBean.getInstance().getConvertUtils().lookup(Date.class));
	}

相关推荐