Kirmani88 Kirmani88 - 7 months ago 27
Java Question

Date Parser parsing every month to January

I have written following code to parse Date into this format

25 July, 2016
. This is what i have done to achieve this.

Date _date;
String datePattern = "dd MMMM, yyyy";
DateFormat formatter = new SimpleDateFormat("yyyy-MM-DD");
SimpleDateFormat format = new SimpleDateFormat(datePattern);
String parseDate;
try {
_date= formatter.parse(date); //date Value is coming from serverin this format = 2016-07-21T16:01:57
parseDate = format.format(_date);
} catch (ParseException e) {

The problem is that, all it converts all Months to
It converts this datet
21 January, 2016

Kindly guide me what i am doing wrong here.


Try this :

    DateFormat userDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); //time format from server
    DateFormat dateFormatNeeded = new SimpleDateFormat("yyyy-MM-DD"); // time format needed
    Date newDate = null;
    try {
        newDate = userDateFormat.parse(date); // this parses server date format
    } catch (ParseException e) {
    //this converts to required date format
    String convertedDate = dateFormatNeeded.format(newDate);
    return convertedDate;