I wish to get the start date & end date of the week, for a week number passed in to the method. For example, if i pass the week number as 51
and the year as 2011
, it should return me start date as 18 Dec 2011
and the end date as 24 Dec 2011
Are there any methods that will help me achieve this?
You can use the following method to get first date and end date of a week
You need to use the
java.util.Calendar
class. You can set the year withCalendar.YEAR
and the week of year withCalendar.WEEK_OF_YEAR
using thepublic void set(int field, int value)
method.As long as the locale is set properly, you can even use
setFirstDayOfWeek
to change the first day of the week. The date represented by your calendar instance will be your start date. Simply add 6 days for your end date.