Java 8 DateFormatter 年月周关键符号区别

Java 8 DateFormatter week of month and year key symbols difference

我是 java.time 的新手。请耐心等待。

有什么区别
  Symbol  Meaning                     Presentation      Examples
  ------  -------                     ------------      -------
    F       week-of-month               number            3
    W       week-of-month               number            4 

不就是

  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

https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

uy 之间的区别已经解决:

WF 之间的区别

a bug in the javadoc for F.

W 是一个月中的第几周,用 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 是一个月中对齐的星期几,如 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.

FDateTimeFormatterSimpleDateFormat 中的行为相似。

示例: 如果您使用 2016-11-07 作为输入,W 将 return 2(该月的第 2 周)但是 F 将 return 7(第一个对齐周的第 7 天,从每月的 1 号开始)。