获取LocalDate的周数(Java 8) [英] Get Week Number of LocalDate (Java 8)
本文介绍了获取LocalDate的周数(Java 8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下格式获取完整LocalDate的周数:
I'm trying to get the Week Number of a full LocalDate with the format:
dd.MM.yyy
我还没有在Java 8 Date API中找到一个返回周数的函数,我试过了创建一个算法,但它没有用。
I haven't found a function in the Java 8 Date API wich returns the Week Number and i have tried to create a algorithm, but it did'nt work.
推荐答案
一个小警告。我还没有测试过这个,但是查看 WeekFields
和 LocalDate.get
,您应该执行以下操作:
One small warning. I haven't tested this yet, but looking at the API documentation of WeekFields
and LocalDate.get
, you should do something like:
LocalDate date = ...;
// Or use a specific locale, or configure your own rules
WeekFields weekFields = WeekFields.of(Locale.getDefault());
int weekNumber = date.get(weekFields.weekOfWeekBasedYear());
这篇关于获取LocalDate的周数(Java 8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文