【发布时间】:2021-11-01 13:32:14
【问题描述】:
我有以下方法来计算给定月份的长度(以秒为单位)。
public static long getNumberOfSecondsInMonth(int year, int month) {
int daysInMonth = YearMonth.of(year, month).lengthOfMonth();
return daysInMonth * HOURS_IN_DAY * SECONDS_IN_AN_HOUR;
}
问题是,这段代码没有考虑 Winter-Time 和 Spring-Time 的 ZoneId。
那么,无论如何我可以将ZoneId 包含在下面的行中吗?
YearMonth.of(year, month).lengthOfMonth();
要点:我知道,我可以初始化YearMonth.now(ZoneId),但是要得到最终答案看起来工作量太大。
【问题讨论】: