private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
houseInfo.setIssuanceDate(Date.valueOf(df.format(date)));在action 中 一个实体类添加当前时间 这种格式的转换哪里除了问题? 009-1-26 16:43:27 org.apache.struts.action.RequestProcessor processException
警告: Unhandled Exception thrown: class java.lang.NumberFormatException
2009-1-26 16:43:27 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.NumberFormatException: For input string: "26 16:43:27"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:456)
at java.lang.Integer.parseInt(Integer.java:497)
at java.sql.Date.valueOf(Date.java:101)
houseInfo.setIssuanceDate(Date.valueOf(df.format(date)));在action 中 一个实体类添加当前时间 这种格式的转换哪里除了问题? 009-1-26 16:43:27 org.apache.struts.action.RequestProcessor processException
警告: Unhandled Exception thrown: class java.lang.NumberFormatException
2009-1-26 16:43:27 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.NumberFormatException: For input string: "26 16:43:27"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:456)
at java.lang.Integer.parseInt(Integer.java:497)
at java.sql.Date.valueOf(Date.java:101)
把你的private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");这句代码改成
private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
构造java.sql.Date的参数应该是yyyy-MM-dd格式的问题严重不清楚 呵呵
public static Date valueOf(String s)将 JDBC 日期转义形式的字符串转换成 Date 值。
参数:
s - 表示 "yyyy-mm-dd" 形式的日期的 String 对象
返回:
表示给定日期的 java.sql.Date 对象 问题是 为什么要把date格式化成字符串,然后又把字符串变回date...?
java.lang.NumberFormatException: For input string: "26 16:43:27" 了
正确的应该是显示 2009-01-26 16:43:27 因为
houseInfo.setIssuanceDate
在实体类中是java.sql.Date 类型 ,所以错误的信息如此: "26 16:43:27"
但是使用java.util.Date 的话 我的DAO类中 代码
pstmt.setDate(9, item.getIssuanceDate());
又报错
那个isuanceDate 是记录发帖时间的 ,必须有准确的时分秒 ,那又不得不使用java.util.date 了
private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
重新写的
java.util.Date d = new java.util.Date();
Date date = new Date(d.getTime());
houseInfo.setIssuanceDate(date);