将java日期转换为oracle日期格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19573613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
converting java date to oracle date format
提问by ramkumar
i am having string as 10-07-1992. i have to convert this to oracle date format like 10-jul-1992. i tried using this
我的字符串为 10-07-1992。我必须将其转换为 oracle 日期格式,如 10-jul-1992。我试过用这个
String date = fqu.getDob();
Date d = new SimpleDateFormat("dd/MM/yyyy").parse(date);
java.sql.Date sqlDate = new java.sql.Date(d.getTime());
System.out.println("sql date"+sqlDate);
this prints like 1992-07-10. but this is not recognized while inserting this value in oracle.
这打印像 1992-07-10。但这在 oracle 中插入此值时无法识别。
i dont need to_cast method. this works only in sql command prompt. i want to do this conversion inside java file.
我不需要 to_cast 方法。这仅适用于 sql 命令提示符。我想在java文件中进行这个转换。
回答by Reji
Can you try
你能试一下吗
Date d = new SimpleDateFormat("dd/MMM/yyyy").parse(date);
回答by Naveen Kumar Alonekar
Use Date format as dd-MMM-yyyy
使用日期格式为 dd-MMM-yyyy
Date d = new SimpleDateFormat("dd-MMM-yyyy").parse(date);
Shows output as
将输出显示为
10-jul-1992