实体
private Date createtime;
public static Advertising FromResultSet(ResultSet rs) throws SQLException
{
Advertising ad = new Advertising();
.......
ad.setCreatetime(rs.getTimestamp("time"));
.......
return ad;
}
}
Dao层
System.out.println(time); // Sun Oct 22 00:00:00 GMT+08:00 2017
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy",Locale.US);
TimeZone tz = TimeZone.getTimeZone("GMT+8");
sdf.setTimeZone(tz);
Date s = null;
try {
s = sdf.parse(time);
System.out.println(s); //Sun Oct 22 00:00:00 CST 2017
System.out.println(strToDate.getTime()); // 1508601600000
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
将时间格式(Sun Oct 22 00:00:00 CST 2017)转换为(1508601600000)即可
db.open();
db.execute(sql,... new java.sql.Timestamp(s.getTime()), ...);