鉴于 LocalDate 我想转换为纪元以来的周数
一种方法是:
LocalDate date = datePicker.getValue(); // input from your date picker
Locale locale = Locale.US;
int weekOfYear = date.get(WeekFields.of(locale).weekOfWeekBasedYear());
And X = find weeks since Epoch to prevYear
And then result = X + weekOfYear
尽管我们可以通过某种方式找到“自纪元以来的周数”,但是否有使用 Java 8 找到它的干净解决方案?
更新:即使上述解决方案也无法工作,因为一周(总是从周日开始)可以跨越两年