用struts2 自带的Data日期类型转换都是不行,于是参照网上的做法写了个类型转换的converter,但是转换总出来一些问题,在myeclipse的console中输出如下:
java.text.ParseException: Unparseable date: "1900-01-01"
at java.text.DateFormat.parse(DateFormat.java:337)...................(不写 了....我的converter类是这样写的:package com.test001.converter;import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;import org.apache.struts2.util.StrutsTypeConverter;import sun.misc.Request;
public class RegisterConverter extends StrutsTypeConverter{
private static final DateFormat[] ACCEPT_DATE_FORMATS = {
new SimpleDateFormat("dd/MM/yyyy"),
new SimpleDateFormat("yyyy-MM-dd"),
new SimpleDateFormat("yyyy/MM/dd")
};
@Override
public Object convertFromString(Map context, String[] values, Class toClass) {
Date date = null;
String[] params = (String[])values;
String datestring = params[0];
for(DateFormat foramt : ACCEPT_DATE_FORMATS)
{
try{
return foramt.parse(datestring);
} catch (Exception e) {
//continue; //这里我直接e打印出来,所以就看到了,如果用continue; 当然就没有警 告提示了...
e.printStackTrace();
}
}
return null;
} @Override
public String convertToString(Map context, Object o) {
Date date = (Date)o;
return new SimpleDateFormat("yyyy-MM-dd").format(date);
}
}
求解啊,日期类型转换........
java.text.ParseException: Unparseable date: "1900-01-01"
at java.text.DateFormat.parse(DateFormat.java:337)...................(不写 了....我的converter类是这样写的:package com.test001.converter;import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;import org.apache.struts2.util.StrutsTypeConverter;import sun.misc.Request;
public class RegisterConverter extends StrutsTypeConverter{
private static final DateFormat[] ACCEPT_DATE_FORMATS = {
new SimpleDateFormat("dd/MM/yyyy"),
new SimpleDateFormat("yyyy-MM-dd"),
new SimpleDateFormat("yyyy/MM/dd")
};
@Override
public Object convertFromString(Map context, String[] values, Class toClass) {
Date date = null;
String[] params = (String[])values;
String datestring = params[0];
for(DateFormat foramt : ACCEPT_DATE_FORMATS)
{
try{
return foramt.parse(datestring);
} catch (Exception e) {
//continue; //这里我直接e打印出来,所以就看到了,如果用continue; 当然就没有警 告提示了...
e.printStackTrace();
}
}
return null;
} @Override
public String convertToString(Map context, Object o) {
Date date = (Date)o;
return new SimpleDateFormat("yyyy-MM-dd").format(date);
}
}
求解啊,日期类型转换........
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货