相关疑难解决方法(0)

如何将格里高利转换为中国农历?

我想使用Greogorian Calendar为中国农历制作一个Android应用程序.

我不知道如何从格里高利转换成中国历法.我怎样才能做到这一点?

java android calendar

9
推荐指数
1
解决办法
6458
查看次数

为什么Java 8 DateTimeFormatter在ResolverStyle.STRICT模式下允许不正确的月份值?

为什么这个测试通过,而月份值显然是无效的(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)

datetime-parsing java-8 java-time

8
推荐指数
1
解决办法
511
查看次数

标签 统计

android ×1

calendar ×1

datetime-parsing ×1

java ×1

java-8 ×1

java-time ×1