Java Date Formatting Help

Hi I have the following date as a string format.

Input

2010-04-20 05:34:58.0

      

Output I want a line like

20, Apr 2010

      

Can anyone tell me how to do this?

+1


a source to share


2 answers


Try the following:



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);

      

+5


a source


You might want to try the following:



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));

      

+5


a source







All Articles