Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between year and year-of-era?

The DateTimeFormatter class documentation defines separate symbols u for year and y year-of-era: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#patterns

What is the difference between year and year-of-era?

like image 715
glerup Avatar asked Mar 12 '15 15:03

glerup


People also ask

What is a week Era year?

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.

What is the difference between year and week year?

While a lower-case yyyy is the year, an upper-case YYYY is the week year. The current week year is usually the same as the current calendar year. But it may not be around New Year's Day. The new week year does not always start on 1 January.


1 Answers

The answer lies in the documentation for IsoChronology

  • era - There are two eras, 'Current Era' (CE) and 'Before Current Era' (BCE).
  • year-of-era - The year-of-era is the same as the proleptic-year for the current CE era. For the BCE era before the ISO epoch the year increases from 1 upwards as time goes backwards.
  • proleptic-year - The proleptic year is the same as the year-of-era for the current era. For the previous era, years have zero, then negative values.

u will give you the proleptic year. y will give you the year of the era.

The difference is mainly important for years of the BC era. The proleptic year 0 is actually 1 BC, it is followed by proleptic year 1 which is 1 AD. The proleptic year can be negative, the year of era can not.

Here is a snippet that will help visualize how it works :

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("'proleptic' : u '= era:' y G");  for (int i = 5; i > -6 ; i--) {     LocalDate localDate = LocalDate.of(i, 3, 14);     System.out.println(formatter.format(localDate)); } 

Output:

proleptic : 5 = era: 5 AD proleptic : 4 = era: 4 AD proleptic : 3 = era: 3 AD proleptic : 2 = era: 2 AD proleptic : 1 = era: 1 AD proleptic : 0 = era: 1 BC proleptic : -1 = era: 2 BC proleptic : -2 = era: 3 BC proleptic : -3 = era: 4 BC proleptic : -4 = era: 5 BC proleptic : -5 = era: 6 BC 
like image 182
bowmore Avatar answered Oct 08 '22 12:10

bowmore