javadatesimpledateformatdate-formatting

Formatting of timestamp


Can you please suggest how to display Timestamp value in format "dd MonthName" format for e.g. "Tue Jun 25 21:56:17 IST 2013". It should be displayed as "25 June". I'm using below code but it is not working.

Date dNow = new Date();
SimpleDateFormat ft = new SimpleDateFormat ("d M");
System.out.println("Current Date: " + ft.format(dNow));

Observed output:

Current Date: 25 6


Solution

  • Use the format as "dd MMMMM" as

    dd: Day in month (2 digit day number)

    MMMMM: Month in year

    SimpleDateFormat sdf = new SimpleDateFormat ("dd MMMMM");
    

    Read more about SimpleDateFormat here

    http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html