5

This question relates to parsing 2-digit years in Java 8 / JSR 310 / threeten.org backport. 2-digit years are an unfortunate fact-of-life that need to be dealt with.

I am only concerned about the ISO calendar. JSR 310 by default assumes a "base year" of 2000 for 2 digit years.

I see that control over the base year is accessible via

DateTimeFormatterBuilder.appendValueReduced(...)

Format patterns provide a convenient mechanism for specifying date formats

dd-MMM-yy
M/d/yy
d/M/yy

I do not see a mechanism to apply a "base year" for 2-digit years after the format pattern has been applied.

Joda-time had DateTimeFormatter.withPivotYear(int pivotYear) as a mechanism to address this problem.

  • In JSR 310, is there a mechanism to apply a base for 2-digit year after specifying a pattern?

  • What is the best-practice recommendation for parsing 2-digit years where the base year may not be 2000?

borjab
  • 11,149
  • 6
  • 71
  • 98
Michael Howard
  • 193
  • 1
  • 8
  • 4
    See my answer on [this post](http://stackoverflow.com/questions/29490893/parsing-string-to-local-date-doesnt-use-desired-century). There is no convenient way to configure the pivot year (also no pattern-based way), but in my answer I have at least demonstrated a way to do so. – Meno Hochschild May 13 '15 at 15:16
  • Meno, Your demonstration of how to combine .appendPattern() & .appendValueReduced() is very helpful. Thank you. – Michael Howard May 14 '15 at 17:34

0 Answers0