我需要一年中的天数,我想使用Java8的新时间api.
但是,我不能这样做,Duration.ofDays(365)因为它没有说明闰年.而且Duration.of(1, ChronoUnit.YEARS)不飞,因为java.time.temporal.UnsupportedTemporalTypeException: Unit must not have an estimated duration
我查看了Period,但它似乎对于从几年到几天都没用.
我觉得我在这里错过了一些东西?如果年份是闰年,我可以写一些东西来增加一天,但似乎我应该能够开箱即用.
如果我有类似的课程
public class Property {
private String id;
private String key;
private String value;
public Property(String id, String key, String value) {
this.id = id;
this.key = key;
this.value = value;
}
//getters and setters
}
Run Code Online (Sandbox Code Playgroud)
我有Set<Property> properties一些属性,我想减少到Map这些Property对象的键和值.
我的大多数解决方案最终都不那么温文尔雅.我知道有一种方便的方法来做这些,Collector但我还不熟悉Java8.有小费吗?