数据库produceTime的类型是datetime。如“2011-04-29 17:40:45”private Date produceTime;
@Column(name = "produceTime", length = 19)
public Date getProduceTime() {
return this.produceTime;
}
public void setProduceTime(Date produceTime) {
this.produceTime = produceTime;
}但是我在页面遍历的时候日期格式是“2011-04-29 17:40:45.0”。
多了一个“.0”。我是用EL表达式获取的。
哪位高手知道是什么问题?
@Column(name = "produceTime", length = 19)
public Date getProduceTime() {
return this.produceTime;
}
public void setProduceTime(Date produceTime) {
this.produceTime = produceTime;
}但是我在页面遍历的时候日期格式是“2011-04-29 17:40:45.0”。
多了一个“.0”。我是用EL表达式获取的。
哪位高手知道是什么问题?
在EL中${produceTime} 实际上调用Timestamp的toString()
也就是说
${produceTime} 与 <% =produceTime.toString();%>等价而Timestamp的toString()的实现为:toString()
public String toString()使用 JDBC 时间戳转义格式编排时间戳。yyyy-mm-dd hh:mm:ss.fffffffff,其中 ffffffffff 指示毫微秒。 覆盖:
类 Date 中的 toString
返回:
使用 yyyy-mm-dd hh:mm:ss.fffffffff 格式的 String 对象
另请参见:
Date.toLocaleString(), Date.toGMTString()看到那个红色的fffffffff 了吧
/**
* Formats a timestamp in JDBC timestamp escape format.
* <code>yyyy-mm-dd hh:mm:ss.fffffffff</code>,
* where <code>ffffffffff</code> indicates nanoseconds.
* <P>
* @return a <code>String</code> object in
* <code>yyyy-mm-dd hh:mm:ss.fffffffff</code> format
*/
public String toString () {