【问题标题】:DateTimeParseException: Text cannot be parsed to a DurationDateTimeParseException:文本无法解析为持续时间
【发布时间】:2022-07-01 21:51:57
【问题描述】:

我遇到了Duration 解析器的问题:

    // import java.time.Duration;
    ...
    Duration d = Duration.parse("1h");
    ...

根据文档,我应该能够使用这个 1h 值,但它给了我以下错误:DateTimeParseException: Text cannot be parsed to a Duration。我从一些配置中检索了1h 值,但为了简单起见,我省略了其他代码。

【问题讨论】:

    标签: java spring-boot datetime


    【解决方案1】:

    您使用的格式不正确,请在下面使用 -

    Duration d = Duration.parse("PT1H");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-29
      • 1970-01-01
      • 2019-02-15
      • 2020-06-10
      • 1970-01-01
      • 2014-07-16
      • 2014-08-16
      • 1970-01-01
      相关资源
      最近更新 更多