简体   繁体   English

如何将Java时间戳转换为MySQL日期时间函数

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM