我有一个字符串形式的日期.我必须将其更改为 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日期的日期转换给出不同的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
“Char 不能被取消引用"错误quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用错误)
Java Switch 语句 - 是“或"/“和"可能的?Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 语句 - 是“或/“和可能的?)
Java替换字符串特定位置的字符?Java Replace Character At Specific Position Of String?(Java替换字符串特定位置的字符?)
具有 int 和 char 操作数的三元表达式的类型是什么What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作数的三元表达式的类型是什么?)
读取文本文件并存储出现的每个字符Read a text file and store every single character occurrence(读取文本文件并存储出现的每个字符)
为什么我需要在 byte 和 short 上显式转换 char 原语Why do I need to explicitly cast char primitives on byte and short?(为什么我需要在 byte 和 short 上显式转换 char 原语?)