例如在mysql中的一張表中存在一個字段opr_time為datetime類型,
在JDBC 中通過rs.getString("opr_time");來獲取使會在日期后面添加".0",
例如日期為:2014-06-01 12:10:20 查詢出來為:2014-06-01 12:10:20.0
解決方法:通過rs.getTimestamp("opr_time")獲取對應的時間戳然后調用toDateStr(Timestamp tt)方法就可以。
public static String toDateStr(Timestamp tt){ if(null!=tt){ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tt); } return ""; }