我尝试使用 java.util.Date 和 java.sql.Date 但在这两种情况下时间部分都没有被保存。
如果日期是 2015-11-16 17:53:49.6
它在 SQL Server 中将其保存为 2015-11-16 00:00:00.000。
最佳答案
来自docs java.sql.Date 的,因为它只表示日期而不是时间(所以时间值将是您得到的 00:00:00.000)。因此,您必须在代码中显式添加时间或更好地使用 java.sql.Timestamp
To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.
关于java - 如何从java保存SQL Server 2014中的日期时间列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33735456/