将XMLGregorianCalendar转换为日期,即"MM/DD/YYYY hh:mm:ss AM" [英] convert XMLGregorianCalendar to date i.e "MM/DD/YYYY hh:mm:ss AM"
问题描述
我有一个XMLGregorianCalendar格式的日期,例如"2013-05-16T09:54:13",我必须将其转换为时间戳记"MM/DD/YYYY hh:mm:ss AM",以便使用Java插入到oracle数据库表中
I have a date in XMLGregorianCalendar format like "2013-05-16T09:54:13" which i have to convert to timestamp "MM/DD/YYYY hh:mm:ss AM" for inserting into oracle database table using java.
我该如何用Java做到这一点?
how can i do this in Java?
推荐答案
您可以执行以下操作以返回Date
:
You can do this to return a Date
:
calendar.toGregorianCalendar().getTime()
我发现来自本教程.从那里,您可以使用 SimpleDateFormat 来将其转换为所需格式的字符串.
I found that code from this tutorial. From there, you can use a SimpleDateFormat to turn it into a string in the format you want.
But, if you're using JDBC to save the date in the database, you probably can pass in the Date
directly with this method:
preparedStatement.setDate(colNum, myDate);
这篇关于将XMLGregorianCalendar转换为日期,即"MM/DD/YYYY hh:mm:ss AM"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!