我想使用Greogorian Calendar为中国农历制作一个Android应用程序.
我不知道如何从格里高利转换成中国历法.我怎样才能做到这一点?
为什么这个测试通过,而月份值显然是无效的(13)?
@Test
public void test() {
String format = "uuuuMM";
String value = "201713";
DateTimeFormatter.ofPattern(format).withResolverStyle(ResolverStyle.STRICT)
.parse(value);
}
Run Code Online (Sandbox Code Playgroud)
使用时态查询时,会DateTimeParseException抛出预期:
DateTimeFormatter.ofPattern(format).withResolverStyle(ResolverStyle.STRICT)
.parse(value, YearMonth::from);
Run Code Online (Sandbox Code Playgroud)
没有TemporalQuery指定时会发生什么?
编辑:13值似乎是一个特殊的值,因为我学到了ΦXocę웃Пepeúpaツ的答案(见Undecimber).
但是,即使使用其他值,例如50,也不会抛出异常:
@Test
public void test() {
String format = "uuuuMM";
String value = "201750";
DateTimeFormatter.ofPattern(format).withResolverStyle(ResolverStyle.STRICT)
.parse(value);
}
Run Code Online (Sandbox Code Playgroud)