JDBC返回结果中的时间函数(getDate--getTime--getTimestamp)详解

ResultSet类的getDate getTime 和getTimestamp方法的区别:
getDate() 只取到天
getTime() 只取时分秒
getTimestamp() 精确到毫秒

正确取得格式为2018-08-27 16:41:10的时间方式如下:

  • Date time1=new Date(rs.getTimestamp(“pub_time”).getTime());//java.util.Date
  • SimpleDateFormat formattime = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
  • String pubtime=formatime.format(time1);

你可能感兴趣的:(1.1.2.1JDBC,☆2.数据库)