[Solved] how to convert Date in to Feb 26, 2016 in java [duplicate]


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

  public static void main(String[] args) throws ParseException {

    String theInDate = "2/20/2016";

    String theInFormat = "MM/dd/yyyy";
    String theOutFormat = "MMM dd, yyyy";

    final SimpleDateFormat theSdfInputFormatter = new SimpleDateFormat(theInFormat);
    final SimpleDateFormat theSdfOutputFormatter = new SimpleDateFormat(theOutFormat);

    final Date theDate = theSdfInputFormatter.parse(theInDate);

    final String theDateText = theSdfOutputFormatter.format(theDate);

    System.out.println(theDateText);

    }
}

You might wantto check the setLinient(true) functionality on the date parser as well.

And with the new Date API

    String theInDate = "2/20/2016";

    String theInFormat = "M/d/yyyy";
    String theOutFormat = "MMM dd, yyyy";

    final DateTimeFormatter theSdfInputFormatter = DateTimeFormatter.ofPattern( theInFormat );
    final DateTimeFormatter theSdfOutputFormatter = DateTimeFormatter.ofPattern(theOutFormat);

    final LocalDate theDate = LocalDate.from( theSdfInputFormatter.parse( theInDate ) );

    final String theDateText = theSdfOutputFormatter.format(theDate);

    System.out.println(theDateText);

Be aware of thread safety. take a look at the javadoc.
This solution works for Java. For Android, as tagged, it should be quite similar.
And even though this is a duplicate answer I hope it helps someone to solve an issue very fast and get an understanding how it works for further self study.

2

solved how to convert Date in to Feb 26, 2016 in java [duplicate]