开发者

Convert Date format from "29/05/2011 00:00:00 ZE8" into "Sat, 28 May 2011"in Java

I am struggling to convert my String "29/05/2011 00:00:00 ZE8" into the following format in "Sat, 28 May 2011" in Java.

This is an abstract of my code. It seems to work but my colleague in Chile gets a date that is 2 years in the future when he runs the code.

SimpleDateFormat df2 = new S开发者_如何学运维impleDateFormat("EEE, dd MMM yyyy");
Date etdDate = df2.parse(OCD_ETD_String);
String OCD_ETD_StringFormatted = dateFormat.format(etdDate);  

Hope someone could shed some light.

Best Regards


You need two different date format strings, one for the "incoming" format and one for the "outgoing" format. Then parse with one and format with the other. Like

SimpleDateFormat in=new SimpleDateFormat("dd/MM/yyyy HH:mm:ss zzz");
SimpleDateFormat out=new SimpleDateFormat("EEE dd MMM yyyy");
Date somedate=in.parse(dateFormatIn);
String dateFormatOut=out.format(somedate);

In your example you are attempting to parse with the desired output format. This won't work: If it was in that format already, you wouldn't need to do any of this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜