A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Java in General
Author
getting the start date for a week number
Dar Var
Ranch Hand
Joined: Oct 12, 2004
Posts: 74
posted
Oct 03, 2005 04:55:00
0
Hi,
I am trying to get the start date for a week when given the week number an year.
My calender setting will be
Calendar gregorianCalendar = new
GregorianCalendar
();
gregorianCalendar.setFirstDayOfWeek(Calendar.MONDAY);
gregorianCalendar.setMinimalDaysInFirstWeek(4);
for example:
if my method is passed in 40/2005 i.e. week 40 in year 2005
The method should pass back 03/10/2005 i.e. 3rd Oct 2005
Ritesh Agrawal
Ranch Hand
Joined: Jan 08, 2004
Posts: 74
posted
Oct 03, 2005 05:32:00
0
Hi Dar,
I have added a couple of lines to your code. Lets see if this is what you were looking for.
import java.util.Calendar; import java.util.GregorianCalendar; public class FirstDayofWeek { public static void main(String[] args) { Calendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setFirstDayOfWeek(Calendar.MONDAY); gregorianCalendar.setMinimalDaysInFirstWeek(4); int numWeekofYear = 40; //INPUT int year = 2005; //INPUT gregorianCalendar.set(Calendar.YEAR , year); gregorianCalendar.set(Calendar.WEEK_OF_YEAR , numWeekofYear); System.out.println( gregorianCalendar.get(Calendar.DAY_OF_MONTH) + "/" + (gregorianCalendar.get(Calendar.MONTH) + 1 ) + "/" + gregorianCalendar.get (Calendar.YEAR)); } } Output: 3/10/2005
Cheers!!!
[ October 03, 2005: Message edited by: Ritesh Agrawal ]
Ritesh<br /> <br />SCJP 1.4<br />IBM Test 340<br />IBM AIX V4.0 Certified Professional<br /> <br />Right actions for the future are the best apologies for wrong ones in the past.<br />- Tyron Edwards
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: getting the start date for a week number
Similar Threads
Method Chaining question
48 hours rule, pls recomment
One more GregorianCalendar question
daysOfWeek function implementation
GregorianDate and week_number
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter