As explained in the other answers, what you want is yyyy
instead of YYYY
.
Now to add further information about the resut you get :
Date String : "Apr 27, 2018, Fri"
Format : "MMM dd, YYYY, EEE"
(YYYY
being week year)
Quoting from How does Java “week year” really work?
On parsing, SimpleDateFormat expects a matching set of values: either
day, month, year or day of week, week in year, week-year. Since you
supplied a week-year but did not supply day of week and week in year,
those to values have been assumed as 1.
You don't have the week in year part (or your format would contain w
), so it is assumed to be 1 .
You end up having friday of the first week of the year 2018, which is :
Jan 05, 2018, Fri
(The day and the month from your date get discarded once the format hits the YYYY
part, and are replaced by the result of the "year week" computing. )