为什么不支持在java.time.Instant中增加几周? [英] Why is adding weeks to java.time.Instant not supported?

查看:153
本文介绍了为什么不支持在java.time.Instant中增加几周?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码:

Instant inFourWeeks = Instant.now().plus(4L, ChronoUnit.WEEKS);

引发异常:

java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Weeks

为什么不支持数周?我理解为什么不支持数月和数月,因为它们使用较小单位的持续时间可能会有所不同.但是 week 的持续时间(7天)是固定的,我可以这样写:

Why are weeks unsupported? I understand why months and years are not supported, because their duration in smaller units may vary. But a week has constant duration (7 days) and I can achieve the same by writing:

Instant inFourWeeks = Instant.now().plus(4L * 7L, ChronoUnit.DAYS);

推荐答案

一周7天抛出的异常并不普遍且恒定.不同的日历系统可能会有所不同.例如,查看每周使用6天的 Akan 日历系统.

It throws UnsupportedTemporalTypeException 7 days week is not universal and constant. It may vary of different calendar system. For example, look on the Akan calendar system which uses 6 days a week.

这篇关于为什么不支持在java.time.Instant中增加几周?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆