Antonio Antonio - 2 months ago 12
Java Question

Java 8 DateFormatter week of month and year key symbols difference

I am new to

. Please, be patient. What is the difference between

Symbol Meaning Presentation Examples
------ ------- ------------ -------
F week-of-month number 3
W week-of-month number 4

isn't it just

Symbol Meaning Presentation Examples
------ ------- ------------ -------
F/W week-of-month number 3


Symbol Meaning Presentation Examples
------ ------- ------------ -------
Y week-based-year year 1996; 96
u year year 2004; 04
y year-of-era year 2004; 04


The difference between u and y has already been addressed: What is the difference between year and year-of-era?

Difference between W and F

There is a bug in the javadoc for F.

W is the week of month, as represented by Weekfields::weekOfMonth:

This represents the concept of the count of weeks within the month where weeks start on a fixed day-of-week, such as Monday.

F is the aligned day of week in month, as represented by ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH:

This represents the concept of the count of days within the period of a week where the weeks are aligned to the start of the month.

F behaves similarly in DateTimeFormatter and SimpleDateFormat.

Example: if you use 2016-11-07 as an input, W will return 2 (2nd week of the month) but F will return 7 (7th day of the first aligned week, which starts on the 1st of the month).