你必须首先parse
的String
使用parse
方法从SimpleDateFormat
。
然后通过由parse
方法返回到另一个SimpleDateFormat
,然后使用format
方法得到你想要的格式的日期Date
对象。
String s = "201307061230202";
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSS"); // format in which you get the String
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // format in which you want the date to be in
System.out.println(sdf1.format(sdf.parse(s)));
的HH
,hh
,KK
和kk
在小时字段中的意义是不同的。我已经使用HH
您可以根据您的要求使用。
H Hour in day (0-23)
k Hour in day (1-24)
K Hour in am/pm (0-11)
h Hour in am/pm (1-12)
来源
2013-07-06 21:06:33
JHS
你到目前为止尝试了什么? –
我已经尝试过了,但是我得到了以下错误:java.text.ParseException:Unparseable date:“20130706234310” – Liviu
我试过SimpleDateFormat和DateTimeFormat – Liviu