Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6569621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:39:18+00:00 2026-05-25T14:39:18+00:00

and thanks for reading me. I have a little problem that is that I

  • 0

and thanks for reading me.

I have a little problem that is that I need to Know the first/last day of a week in a month and a year, so:

public String getFirstDayOfWeekAndMonth(int year, int month, int week){
   Calendar weekCalendar = Calendar.getInstance();
   weekCalendar.clear();
   weekCalendar.set( Calendar.YEAR, year );
   weekCalendar.set( Calendar.MONTH, month-1); // zero-based
   weekCalendar.set( Calendar.WEEK_OF_YEAR, week );

   return... ?
}

For example for the next calendar:

Month    Week     M   T   W   T   F   S   S           FirstDay    LastDay
          1               1   2   3   4   5              1           5
          2       6   7   8   9   10  11  12             6           12
  1       3       13  14  15  16  17  18  19             13          19
          4       20  21  22  23  24  25  26             20          26
          5       27  28  29  30                         27          30

          5                       1   2   3              1           3
          6       4   5   6   7   8   9   10             4           10
  2       7       11  12  13  14  15  16  17             11          17
          8       18  19  20  21  22  23  24             18          24
          9       25  26  27  28                         25          28

          9                       1   2   3              1           3
  3       10      4   5   6   7   8   9   10             4           10
                     ...

I have problems with the weeks that are in 2 months (on example 5 and 9). Could you help me please?

Thank You very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:39:19+00:00Added an answer on May 25, 2026 at 2:39 pm

    Well, I have develop a method that returns the first and the last day, wothin any other library:

    private static int getFirstDayOfWeek(int year,int month,int week){
        return getFirstLastDayOfWeek(true,year,month,week);
    }
    
    private static int getLastDayOfWeek(int year,int month,int week){
        return getFirstLastDayOfWeek(false,year,month,week);
    }
    
    private static int getFirstLastDayOfWeek(boolean first, int year,int month,int week){
        int exit = 0;
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.WEEK_OF_YEAR, week);
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month-1);
        if (!first)
            calendar.add(Calendar.DAY_OF_MONTH, 6);
        // 1st day of the week
        Date date = calendar.getTime();
        // The month and the day of the 1st day of the week
        int theMonth = Integer.valueOf( getInstance().getStrDate(date,"MM") );
    
        if (theMonth!=month)
            exit = (first?1:new GregorianCalendar(year, month-1, 1).getActualMaximum(Calendar.DAY_OF_MONTH));
        else
            exit = Integer.valueOf( getInstance().getStrDate(date,"d") );
        return exit;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got yet another deployment problem. What I have: little Windows Forms application that
Thanks for reading this. I have no idea why this is throwing a NullReferenceException
Thanks for reading. I have done a search, read multiple posts (lost count) and
I have a little sketch program that I've managed to throw together using Quartz2D,
I have a little problem over here with the jQuery Walidate plugin ( http://jquery.dop-trois.org/walidate/
I have created a little Python egg (with setuptools) that I want to install
I have been doing some reading and a little bit confused, let me explain.
I have a nice little app on the app store that does pretty well
Thanks to reading about error handling on StackOverflow , I discovered Mz-Tools. However, I
Firs of all thanks for reading this. I'm having trouble updating the progress from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.