Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: GregorianCalendar - How to figure out how many days in all weeks of March, 2013?

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default GregorianCalendar - How to figure out how many days in all weeks of March, 2013?

    HI,
    I could calculate the number of weeks in any month and year using following method.

    public void calWeeksAndDays(int month, in year)
    {
    GregorianCalendar cal = new GregorianCalendar(year, month, 1);

    int weeks = cal.getActualMaximum(WEEK_OF_MONTH);

    }

    This works as expected, but now how do I figure out how many days are in each of the weeks that I got from above?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: GregorianCalendar - How to figure out how many days in all weeks of March, 2013?

    Aren't there 7 days in each week?

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GregorianCalendar - How to figure out how many days in all weeks of March, 2013?

    Not necessarily. For example: March 2013 has actually 4 full weeks and two partial ones. The first week of March has only 2 days, i.e. Thursday March 1 and Friday March 2. While the last week of March has only 1 day, that is Sunday Mar 31.

    So that's what I want to figure out.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: GregorianCalendar - How to figure out how many days in all weeks of March, 2013?

    Ohhhh.

    So isn't the number of days in the partial week = number of days in the month less the number of full weeks * 7?

  5. #5
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: GregorianCalendar - How to figure out how many days in all weeks of March, 2013?

    Hello.
    Check the name of the first day of the month. Based on that you will know whether its a partial week or full week. If its partial week you will know how many days. If its full then its 7 days. You will also know how many maximum days are there in that month.
    After finishing with first week start increments of seven until you cross the maximum days. If you have crossed the maximum days then decrement by 7 and count the remaining days. Those will be the number of days for the last week.

    Syed.

  6. #6
    Junior Member
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: GregorianCalendar - How to figure out how many days in all weeks of March, 2013?

    Quote Originally Posted by syedbhai View Post
    Hello.
    Check the name of the first day of the month. Based on that you will know whether its a partial week or full week. If its partial week you will know how many days. If its full then its 7 days. You will also know how many maximum days are there in that month.
    After finishing with first week start increments of seven until you cross the maximum days. If you have crossed the maximum days then decrement by 7 and count the remaining days. Those will be the number of days for the last week.

    Syed.
    Thankyou so much for everyone's feedback. This did give me ideas how to solve the problem. Thanks rsinha

Similar Threads

  1. Edition March 2002 -J2ME IN A NUTSHELL-O'Reilly
    By delhiris1 in forum Android Development
    Replies: 2
    Last Post: July 11th, 2012, 02:22 PM
  2. GregorianCalendar problems
    By Crixus in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 24th, 2011, 10:19 AM
  3. [SOLVED] GregorianCalendar
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 30th, 2009, 04:30 AM