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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:00:35+00:00 2026-06-13T18:00:35+00:00

Using Java’s Calendar or something else, let’s say I set the date to 2012-10-26.

  • 0

Using Java’s Calendar or something else, let’s say I set the date to 2012-10-26. I want this date to be the first day of a year. Is it possible to get the week number of a specific date -let’s say it’s 2012-12-10- assuming that the first week of the year starts from 2012-10-26?

I know my question sounds a little weird, but I could use any useful input.

Thanks.

–Details

I have a database table called WeeklySchedule. In this table I have columns starting from Week1 to Week52, and every column have some data about the days of that week. Unfortunately, Week1 is not really the first week of the year. I need to do my calculations assuming that Week1 starts from 2012-08-26.

  • 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-06-13T18:00:36+00:00Added an answer on June 13, 2026 at 6:00 pm

    Here’s one approach using the Calendar API:

    private static final Calendar START_CAL = createAugust26th2012Cal();
    
    public int getWeekNumber(Calendar someCal) {
        int theWeek = someCal.get(Calendar.WEEK_OF_YEAR);
        int weekCount = 0;
        while (theWeek != START_CAL.get(Calendar.WEEK_OF_YEAR)) {
            someCal.add(Calendar.WEEK_OF_YEAR, -1);
            theWeek = someCal.get(Calendar.WEEK_OF_YEAR);
            weekCount++;
        }
        return weekCount;
    }
    

    Or you could get the diff (in millis) between two calendars and divide the result by the number of millis in a week:

    If you use this approach, don’t forget to take TimeZones and Daylight Saving Time into account.

    I can’t remember exactly what the code looks like to compensate for DST, but I think it’s something like this:
    (I can’t quite remember if you add the offset to or subtract the offset from the two operands)

    private static final long ONE_WEEK_MILLIS = 1000 * 60 * 60 * 24 * 7;
    
    public int getWeeksBetween(Calendar calOne, Calendar calTwo) {
        long millisOne = calOne.getTime().getTime();
        long millisTwo = calTwo.getTime().getTime();
        long offsetOne = calOne.getTimeZone().getOffset(millisOne);
        long offsetTwo = calTwo.getTimeZone().getOffset(millisTwo);
        long diff = (millisTwo - offsetTwo) - (millisOne + offsetOne );
        return diff / ONE_WEEK_MILLIS;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Java (1.6) I want to split an input string that has components of
Using Java sockets, I made a simple server. This works because it sends data
While using Java's switch case, it excepts only char and int, but I want
Using Java, is there a way to look at some content, say, String representation
Using java.util.logging.Logger to output some log to the console just like this: public static
Using Java is it possible to capture the speaker output? This output is not
Using JAVA framework i want to achieve the following task. hot code(jar) deployment which
Using Java regex pattern I want to match the & symbol. But it should
Using java code, it is possible to sort german umlauts correctly with something like
using Java. the List is sorted so I want to use binary search. I'd

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.