如何在Joda-Time中指定哪个世纪的日期应该被解析 [英] How to specify which century a date should be parsed in Joda-Time

查看:125
本文介绍了如何在Joda-Time中指定哪个世纪的日期应该被解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些人力资源记录的日期格式为 dd / MM / yy ,我将其归一化为 dd-MM-yyyy 使用 Joda-Time
所以例如,以下记录按如下标准化:

 输入输出
30/01/14 - > 30-01-2014
15/07/99 - > 15-07-1999
24/03/84 - > 24-03-1984

根据各种标准(人员寿命平均长短,公司周边,...),我可以假设年份 99 可能是指。



但是,如果我想指定 99 1899 或其他一年以 99 ,我该怎么做?



我正在阅读 DateTimeFormatter 模式,以及解释 here ,它看起来像 CenturyOfEra 字段 C 可能是我想要使用的,但不清楚我会如何使用它。

解决方案

如果我正确理解问题,它被称为数据透视年: http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormatter.html# withPivotYear%28int%29



CenturyOfEra只是我们当前的世纪 - XXI,这么多科幻作家几十年前就梦想了。 / p>

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.

解决方案

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.

这篇关于如何在Joda-Time中指定哪个世纪的日期应该被解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆