数据库SQL常用日期转换--Timestamp

SQL常用日期转换–Timestamp

util.Date转sql格式:yy-MM-dd HH:mm:ss

pstm.setTimestamp(3, new java.sql.Timestamp(student.getAdddate().getTime()));

sql.Date转util.Date格式:yy-MM-dd HH:mm:ss

Date adddate = new java.util.Date(rs.getTimestamp(“adddate”).getTime());

Servlet转格式:yy-MM-dd HH:mm:ss

/*转换为JSON并设定时间格式
方法一:*/
resp.getWriter().write(JSON.toJSONStringWithDateFormat(hm, “yyyy-MM-dd HH:mm:ss”));

/*转换为JSON并设定时间格式
方法二:*/
resp.getWriter().write(JSONObject.toJSONStringWithDateFormat(hm, “yyyy-MM-dd HH:mm:ss”));


此处使用的是fastjson插件方法转化


你可能感兴趣的:(java)