views:

59

answers:

2

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 ?

+5  A: 

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);
Andrew Hare
How to construct yourDate. I have it in string format
Bragboy
one thing with this pattern (and mine, below): the month will be printed with a dot, depending on the locale. In french: "Apr."
Séb
+5  A: 

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));
Séb