我使用java Duration between方法计算到LocalTime和LocalDateTime之间的持续时间,当我将localTime用作该方法的第一个参数时,它起作用了,但是当我颠倒顺序时,它给出了DateTimeException异常:
这项工作很好:
LocalTime t1 = LocalTime.now();
LocalDateTime t2 = LocalDateTime.now();
System.out.println(Duration.between(t1, t2));
Run Code Online (Sandbox Code Playgroud)
当我扭转农业生产时,它给了我一个例外:
LocalTime t1 = LocalTime.now();
LocalDateTime t2 = LocalDateTime.now();
System.out.println(Duration.between(t2, t1));
Exception in thread "main" java.time.DateTimeException: Unable to obtain LocalDateTime from TemporalAccessor: 16:32:18.553 of type java.time.LocalTime
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么我得到这个异常感谢您的帮助:=)
| 归档时间: |
|
| 查看次数: |
82 次 |
| 最近记录: |