我有一个字符串形式的日期.我必须将其更改为 Sql Date.所以为此我使用了以下代码.
I have a string form of Date. I have to change it to Sql Date. so for that i have used the following code.
String startDate="01-02-2013";
SimpleDateFormat sdf1 = new SimpleDateFormat("dd-mm-yyyy");
java.util.Date date = sdf1.parse(startDate);
java.sql.Date sqlStartDate = new java.sql.Date(date.getTime());
当我使用上面的代码并运行它时.我得到以下输出.
when i used the above code and run that. I got the following output.
2013-01-01.
此处月份未正确转换.
请告诉我问题出在哪里并提供示例代码以获得正确的结果?
Here Month is not converted correctly.
Please tell me where is the problem and provide sample code to get correct result?
mm
是 minutes.你想要 MM
个月:
SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy");
不要难过 - 这个错误经常出现.
Don't feel bad - this exact mistake comes up a lot.
这篇关于Java中从字符串到sql日期的日期转换给出不同的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!