1、用Java新增的java.time.LocalDate
LocalDate.now().get(ChronoField.ALIGNED_WEEK_OF_MONTH); // 3
2、用java.util.Calendar
Calendar.getInstance().get(Calendar.DAY_OF_WEEK_IN_MONTH); // 3
以上两种方法返回的都是3,但是我看日历今天(2017-12-19)明明是12月的第4周才对啊!!!
查阅官方文档:
For example, in a calendar systems with a seven day week, the first aligned-week-of-year starts on day-of-year 1, the second aligned-week starts on day-of-year 8, and so on. Thus, day-of-year values 1 to 7 are in aligned-week 1, while day-of-year values 8 to 14 are in aligned-week 2, and so on.
1到7为第一周,8到14为第二周......扑街,感觉就是除以7再向上取整啊!
请问:**_按照我的计算方式_,有大神知道Java中有自带的API直接获取周数的吗?或者说有什么方法可以很机智快捷地算出当天对应的周数吗?**