将XMLGregorianCalendar转换为日期,即"MM/DD/YYYY hh:mm:ss AM" [英] convert XMLGregorianCalendar to date i.e "MM/DD/YYYY hh:mm:ss AM"

查看:464
本文介绍了将XMLGregorianCalendar转换为日期,即"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.

但是,如果使用JDBC将日期保存在数据库中,则可以直接使用

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆