如何获得某个月的周数? [英] How to get week numbers of a certain month?
问题描述
我只想问一下获得某个月的周数的有效方法。我有一个月号和功能的功能; year作为参数,函数的返回值应该是一个int数组,其中包含特定月份的周数。(如下......)
I just wanna ask what is the efficient way to get the week numbers of a certain month. I have a function with month number & year as arguments, the return value of the function should be a int array which contain the week numbers of the specific month.(like following...)
public int[] getWeeksOfMonth(int month, int year){
//what's the efficient way to implement this??
}
推荐答案
类可以为您提供帮助。
The WEEK_OF_YEAR
attribute of the Calendar
class can be usefull for you.
创建一个新日期,该日期将是给定的月份。获取当天的一周,假设你有开始
价值。
Create a new date that will be the first day of the given month. Get the week of the year for this day, let say you got start
value.
创建一个新日期,将是给定月份的最后一天。获取当天的一周,所以现在你得到结束
值。
Create a new date that will be the last day of the given month. Get the week of the year for this day, so now you got end
value.
最后,创建一个简单的 int []
将包含从开始
到结束
的值。
Finally, create a simple int[]
that will contains values from start
to end
.
这篇关于如何获得某个月的周数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!