Forums Register Login

How to get weeks for a particular year with Calendar object

+Pie Number of slices to send: Send
How to get weeks for a particular year with Calendar object? What I want is, starting from the first week of a particular year till the end, I need the start date of all the weeks considering Sunday as the first day. For eg. For year 2011 starting from month of January I need all the start dates of every week. 2 Jan 2011- 8 Jan -2011, 9 Jan 2011- 15 Jan 2011 etc.....

Kindly let me know if you have any solution to this...
+Pie Number of slices to send: Send


would set the calendar to the Sunday of the week in question. Probably you can then add 7 to the calendar to get the rest of the sundays.

And Welcome to Javaranch.
+Pie Number of slices to send: Send
Thanks Sridhar.

But what I need is maybe an array of Dates/Objects that hold the values of all weeks for a particular year.
+Pie Number of slices to send: Send
Using Sridhar's suggestion and Calendar's add() method you can generate the calendar objects you need and store them in the collection of your choice. Try coding it and come back if you need help.
Something about .... going for a swim. With this tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1924 times.
Similar Threads
Java Calendar vs Java.util.Date
Number of days between the 2 given dates.
How to get end week date from given start date??
daysOfWeek function implementation
week days
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:32:38.