-1

I will get straight to the point, my goal it so change

2018-05-24

Into

May 24, 2018.

Here is my current code:

    String content = "2018-05-24";
    SimpleDateFormat old = new SimpleDateFormat("yyyy-mm-dd");
    Date oldDate = old.parse(content);
    SimpleDateFormat current = new SimpleDateFormat("MMMM dd, yyyy.");
    String newDate = current.format(oldDate);
    System.out.println(newDate);

But running that produces:

January 24, 2018.

I am not sure why this is telling me January. I know I have it wrong, I have searched StackOverFlow for similar questions, but maybe I am not doing something right. Any advice?

David
  • 179
  • 1
  • 1
  • 10

1 Answers1

1

It's because you're using mm for month when it should be MM:

SimpleDateFormat old = new SimpleDateFormat("yyyy-MM-dd");

This outputs:

May 24, 2018.
Jacob G.
  • 28,856
  • 5
  • 62
  • 116