Help needed in formatting date in Java

醉酒当歌 提交于 2019-12-11 10:39:01

问题


Hi I have the following date as String format.

Input

2010-04-20 05:34:58.0

Output I want the string like

20, Apr 2010

Can someone tell me how to do it ?


回答1:


Try this:

DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");  
DateFormat outputFormat = new SimpleDateFormat("dd, MMM yyyy");

Date yourDate = inputFormat.parse("2010-04-20 05:34:58.0");
String formattedDate = outputFormat.format(yourDate);



回答2:


You might want to try this:

SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date = inFormat.parse( "2010-04-20 05:34:58.0");

SimpleDateFormat outFormat = new SimpleDateFormat("dd, MMM yyyy");
System.out.println(outFormat.format( date));


来源:https://stackoverflow.com/questions/2675666/help-needed-in-formatting-date-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!