Java 8's DateTimeFormatter
class has a method, ofPattern(String pattern)
, that lets you define a format from a string of A-z
, a-z
letters. The examples don't clarify the difference between y
, year-of-era and Y
, week-based-year. What is it?
Symbol Meaning Presentation Examples ------ ------- ------------ ------- y year-of-era year 2004; 04 Y week-based-year year 1996; 96
In a week-based-year, each week belongs to only a single year. Week 1 of a year is the first week that starts on the first day-of-week and has at least the minimum number of days. The first and last weeks of a year may contain days from the previous calendar year or next calendar year respectively.
“Week year” is intended to be used for week dates, e.g. “2015-W01-1”, but is often mistakenly used for calendar dates, e.g. 2014-12-29, in which case the year may be incorrect during the last week of the year. If you are formatting anything other than a week date, you should use the year specifier “yyyy” instead.
The extra week is sometimes referred to as a leap week, although ISO 8601 does not use this term. Weeks start with Monday and end on Sunday. Each week's year is the Gregorian year in which the Thursday falls. The first week of the year, hence, always contains 4 January.
The week number is the count of weeks that have passed in the year up to the end of the current week. For example, if it's the second week of the year, the week number is 2. The week where Jan 1 falls counts as the first week for the following year.
That's year value for "year-week" style dates, as in 2006-W52. It may be off the year-of-era value by +1 or -1 if the week in question straddles year boundary.
See http://en.wikipedia.org/wiki/ISO_8601#Week_dates
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With