Question

How can I convert this date 26-11-2013 in this format nov 26. I have tried many things but didn't work for me. Like

SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
        String dateInString = "26-11-2013";
Date date = formatter.parse(dateInString);
            System.out.println(date);
Was it helpful?

Solution

You will have to use another formatter for the desired output format.

SimpleDateFormat outputFormat = new SimpleDateFormat("MMM dd");
SimpleDateFormat inputFormat = new SimpleDateFormat("dd-MM-yyyy");
String dateInString = "26-11-2013";
Date date = inputFormat.parse(dateInString);
System.out.println(outputFormat.format(date));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top