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 7693085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:00:10+00:00 2026-05-31T21:00:10+00:00

I have one problem with android calendar programming, so If there are 2 months

  • 0

I have one problem with android calendar programming, so
If there are 2 months on one week, android write me name of old month. I want him to write something like (old month-new month).

My Code is as follows

Calendar wek = Calendar.getInstance(Locale.US);
wek.add(Calendar.WEEK_OF_YEAR,r);
SimpleDateFormat gm = new SimpleDateFormat("MMM yyy");
mes.setText(gm.format(wek.getTime()));
  • 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-31T21:00:12+00:00Added an answer on May 31, 2026 at 9:00 pm

    The reason it does this is because when looking at a date represented by a week, it only looks at the first day in the week. You’d need to manually check first and last days of the week and, if they are in a different month, then format the date manually. You also need to be careful about the week overlapping the years as well. Something like this:

    Calendar wek = Calendar.getInstance(Locale.US);
    wek.add(Calendar.WEEK_OF_YEAR,r);
    
    //this will set your calendar onto the first day of the week
    int w = wek.get(Calendar.WEEK_OF_YEAR);
    int y = wek.get(Calendar.YEAR);
    wek.clear();
    wek.set(Calendar.YEAR, y);
    wek.set(Calendar.WEEK_OF_YEAR, w);
    //get the month and year of the first day of the week
    int m1 = wek1.get(Calendar.MONTH);
    int y1 = wek1.get(Calendar.YEAR);
    
    //get the date for the end of the week and its month and year
    Calendar w2 = wek;
    w2.add(Calendar.DATE, 6);
    int m2 = w2.get(Calendar.MONTH);
    int y2 = w2.get(Calendar.YEAR);
    
    if(m1 == m2) {
        //if the two months are the same, then just format the date
        SimpleDateFormat gm = new SimpleDateFormat("MMM yyyy");
        mes.setText(gm.format(wek.getTime()));
    }
    else if(y1 == y1) {
        //different months, same year - format as "MMM - MMM yyyy"
        SimpleDateFormat gm = new SimpleDateFormat("MMM");
        SimpleDateFormat gy = new SimpleDateFormat("yyyy");
        mes.setTextText(gm.format(wek.getTime()) + " - " +
                        gm.format(w2.getTime()) + " " +
                        gy.format(wek.getTime()));
    }
    else {
        //Different months and different years - format as "MMM yyyy - MMM yyyy"
        SimpleDateFormat gm = new SimpleDateFormat("MMM yyyy");
        mes.setTextText(gm.format(wek.getTime()) + " - " +
                        gm.format(w2.getTime()));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one problem , I want to get some data from XML file
I have one problem, I learn how work with socket and I write programm
I have one problem with Android SQLite database. I have one table which contains
i am new in android development and i have one problem with redirect the
I have one problem , i want to refer particular file in my system
I have one process running in android device the problem is process is going
I am working on facebook android application but there is one problem i am
I have one problem to work with NSMutableData . I defined one NSMutableData *receivedData
i have one problem when i sort the NSMutablearray using date and time wise.
I'm almost finished with my program, but I have one problem that I can't

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.