`uuuu` versus `yyyy` in `DateTimeFormatter` formatting pattern codes in Java?
<p>The <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/format/DateTimeFormatter.html" rel="noreferrer"><code>DateTimeFormatter</code></a> class documentation says about its formatting codes for the year:</p>
<blockquote>
<p>u       year                        year              2004; 04</p>
<p>y       year-of-era                 year              2004; 04</p>
<p>…</p>
<p><strong>Year:</strong> The count of letters determines the minimum field width below which padding is used. If the count of letters is two, then a reduced two digit form is used. For printing, this outputs the rightmost two digits. For parsing, this will parse using the base value of 2000, resulting in a year within the range 2000 to 2099 inclusive. If the count of letters is less than four (but not two), then the sign is only output for negative years as per SignStyle.NORMAL. Otherwise, the sign is output if the pad width is exceeded, as per SignStyle.EXCEEDS_PAD.</p>
</blockquote>
<p>No other mention of “era”.</p>
<p>So what is the difference between these two codes, <code>u</code> versus <code>y</code>, <code>year</code> versus <code>year-of-era</code>?</p>
<p>When should I use something like this pattern <code>uuuu-MM-dd</code> and when <code>yyyy-MM-dd</code> when working with dates in Java?</p>
<p>Seems that example code written by those in the know use <code>uuuu</code>, but why?</p>
<p>Other formatting classes such as the legacy <a href="http://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html" rel="noreferrer"><code>SimpleDateFormat</code></a> have only <code>yyyy</code>, so I am confused why java.time brings this <code>uuuu</code> for “year of era”.</p>