[英]How to convert Java Timestamp to mySQL datetime function
My code uses Java.sql.Timestamp
to store an update date. 我的代码使用
Java.sql.Timestamp
存储更新日期。 I want to take that date and store it into a mySQL datetime object. 我想获取该日期并将其存储到mySQL datetime对象中。 My problem is that the
Java.util.Timestamp
returns a date in the format of 2013-12-09 00:00:00.00 but the mySQL colunmn wants the format in 2013-12-09 00:00:00 . 我的问题是
Java.util.Timestamp
返回格式为2013-12-09 00:00:00.00的日期,但是mySQL colunmn希望格式为2013-12-09 00:00:00 。 So it looks like I need to trim off the .00 of the java.sql.Timestamp
. 因此,看起来我需要删减
java.sql.Timestamp
的.00。
您无需在mysql中将时间戳记作为String插入,只需将其视为java.sql.Timestamp
并使用PreparedStatement
正确设置值即可
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.