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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:32:30+00:00 2026-05-22T02:32:30+00:00

I have a program where it relies heavily on identifying the week number for

  • 0

I have a program where it relies heavily on identifying the week number for the year. I have done the leg work and figured out all the problems that will cause and settle with this method. I works perfect for years that have 53 weeks and such. My only issue is that when I run it on my emulator for 2.2 it works perfect, like this is week 19 and its correct. when I run it on my phone a G1, the week shows 20. How do I fix this?

Here is my week code:

/**
 * Format the date into a number that is the year*100 plus the week i.e. 2008 and its week 11
 * would show as 811
 * @param - String of a date to create a week id, must be in format of 2011-01-31 (YYYY-MM-DD)
 * @return returns next weeks id
 */
public static int getWeekId(String date){

    // Set the first day of week to Monday and set the starting new year weeks
    // as a full first week in the new year.
    Calendar c = Calendar.getInstance();
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.setMinimalDaysInFirstWeek(7);

    if (!date.equalsIgnoreCase("")) {
        String[] token = date.split("-", 3);
        int year = Integer.parseInt(token[0]);
        int month = Integer.parseInt(token[1])-1; // months are 0-11 stupid..
        int day = Integer.parseInt(token[2]);
        c.set(year, month, day);
    }


    int yearWeek = ( (c.get(Calendar.YEAR) - 2000)*100 + (c.get(Calendar.WEEK_OF_YEAR)));

    Log.d("getWeekId()"," WEEK_OF_YEAR: " + c.get(Calendar.WEEK_OF_YEAR));

    return yearWeek;

}
  • 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-22T02:32:30+00:00Added an answer on May 22, 2026 at 2:32 am

    (I’d leave this in a comment, but my account does not yet have commenting permissions.)

    When called with 2011-01-01, the code currently returns 1152. Is this as intended?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a self-executable jar program that relies heavily on Spring Integration. The problem
I have program that runs fast enough. I want to see the number of
I have a program that spits out both standard error and standard out, and
I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that spits out an Excel workbook in Excel 2003 XML
I have a Java application whose UI relies heavily on audio. On Windows and
I have written a program that relies on a proxy to function. I now
I have a program which relies on the clock-time to do some recurring tasks.
I'm writing a Java program for my work-study program which relies on the RXTX
I currently have a program I have compiled in x86_64, it relies on quite

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.