问题描述
我想在java中将字符串Date转换为Timestamp。我写了以下编码。我已声明date1的日期是:7-11-11 12:13:14。
I want to convert string Date into Timestamp in java. The following coding i have written.I have declare the date for date1 is: 7-11-11 12:13:14.
SimpleDateFormat datetimeFormatter1 = new SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss");
Date lFromDate1 = datetimeFormatter1.parse(date1);
System.out.println("gpsdate :" + lFromDate1);
Timestamp fromTS1 = new Timestamp(lFromDate1.getTime());
我想将7-11-11 12:13:14此字符串日期转换为时间戳。现在我的输出是0007-11-11 00:13:14.000000 +05:30:00但我希望(7-11-11 12:13:14)这种格式的时间戳日期。谁能帮帮我吗。谢谢。
I want to convert 7-11-11 12:13:14 this string date into timestamp. Now i got the output is 0007-11-11 00:13:14.000000 +05:30:00 but i want ( 7-11-11 12:13:14) this format Timestamp date. Can anyone please help me. Thank you.
推荐答案
您需要做的就是更改构造函数到:
MM-dd-yyyy HH:mm:ss。
All you need to do is change the string within the java.text.SimpleDateFormat
constructor to:"MM-dd-yyyy HH:mm:ss".
只需使用适当的字母构建上述字符串即可匹配您的输入日期。
Just use the appropriate letters to build the above string to match your input date.
这篇关于如何在java中将字符串日期转换为Timestamp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!