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

版权声明:版权声明:本文为博主原创文章,欢迎声明转载,博客地址: https://blog.csdn.net/c851204293/article/details/82110815

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);

猜你喜欢

转载自blog.csdn.net/c851204293/article/details/82110815