如何获得某个月的周数? [英] How to get week numbers of a certain month?

查看:90
本文介绍了如何获得某个月的周数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想问一下获得某个月的周数的有效方法。我有一个月号和功能的功能; 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??
}


推荐答案

属性code>日历 类可以为您提供帮助。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆