[英]How to convert “2019-08-07T14:00:00-0400” to SQL DATETIME format in Java?
I couldn't pass in 2019-08-07T14:00:00-0400
to a stored procedure in SQL Server that takes a param in DATETIME
. 我无法在2019-08-07T14:00:00-0400
给SQL Server中在DATETIME
接受参数的存储过程。
So how can I convert it to this format YYYY-MM-DD HH:MM:SS.SSS
in Java prior to calling the stored procedure? 那么在调用存储过程之前,如何在Java中将其转换为YYYY-MM-DD HH:MM:SS.SSS
格式?
You can make use of SimpleDateFormat
class for reference visit here 您可以使用SimpleDateFormat
类作为参考,请访问此处
SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ");
Date date = df.parse("2019-08-07T14:00:00-0400");
You will get java.util.Date
object in return which in turns you can use to store in database. 您将获得java.util.Date
对象作为回报,您可以依次使用它存储在数据库中。
If you want to convert it in SQL queries you can use below query. 如果要在SQL查询中进行转换,可以使用以下查询。
declare @abc nvarchar(19)='2019-08-07T14:00:00-0400'
select CONVERT(DATETIME,convert(varchar, @abc,121))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.