This is due to the format you used as "yyyy-MM-DD"
. The parser will parse in the sequence way:
- Your input value is
"2018-03-08"
yyyy
– will bring to the year 2018MM
– will bring to the month MARCH
But what is DD
? It’s the number of the days from the beginning of the year.
So here it moved back to 8th day on this year (2018) which means January 8th.
That’s why you are seeing January instead of March.
solved Java parse date string returns wrong month [duplicate]