How to specify which century a date should be pars

2020-04-20 07:25发布

问题:

I have some HR records whose dates are formatted as dd/MM/yy, and I am normalizing them to dd-MM-yyyy using Joda-Time. So for example, the following records are normalized as follows

  Input        Output
30/01/14 --> 30-01-2014
15/07/99 --> 15-07-1999
24/03/84 --> 24-03-1984

Based on various criteria (average length of human lifespan, when company has been around, ... ), I can assume what year 99 might refer to.

However, if I wanted to specify that 99 refers to 1899 or some other year ending in 99, how would I do this?

I am reading over the docs for the DateTimeFormatter patterns, as well as the explanations here, and it looks like CenturyOfEra field C might be what I want to use, but it isn't obvious how I would use it.

回答1:

If I understand the question correctly, it is referred as "Pivot Year": http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormatter.html#withPivotYear%28int%29

The CenturyOfEra is just our current century - XXI, the one which so many sci-fi authors dreamed about few decades back.