How to specify which century a date should be parsed in Joda-Time

不打扰是莪最后的温柔 提交于 2019-12-02 14:13:45

问题


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.



来源:https://stackoverflow.com/questions/25246800/how-to-specify-which-century-a-date-should-be-parsed-in-joda-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!