将Date存入数据库的两种方式

时间:2020-05-20 20:38:22   收藏:0   阅读:115

方式一:

  将java.util.Date()转为java.sql.Date(),即可通过sql语句存入数据库

  Date date = new Date();

  java.sql.Date sqlDate = new java.sql.Date(date.getTime());

 

方式二:

  转换为字符串传入

  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

  Date date = new Date();

  String sdfDate = sdf.format(date);

 

原文:https://www.cnblogs.com/Rhettttt/p/12925688.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!