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

  • Home
  • SEARCH
  • 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 6803791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:23:15+00:00 2026-05-26T19:23:15+00:00

Let’s look at the following code snippet in Java. package demo; import java.util.Calendar; final

  • 0

Let’s look at the following code snippet in Java.

package demo;

import java.util.Calendar;

final public class Main
{
    public static void main(String[] args)
    {
        Calendar cal = Calendar.getInstance();
        cal.set(2011, 11, 11);   //Setting a date to itself.

        System.out.println(cal.get(Calendar.YEAR) + " " 

        + cal.get(Calendar.WEEK_OF_YEAR) + " 

       " + cal.get(Calendar.DAY_OF_YEAR));
    }
}

In the above simple code, I’m temporarily (and explicitly) setting the current date to itself which is 2011-11-11 using the method cal.set(2011, 11, 11);. Accordingly, I get the output 2011 51 345, the current year 2011, the week of the year 51 and the day of the year 345.


When I leave a comment on that line which is cal.set(2011, 11, 11);, I get the result, 2011 46 315 the current year, the current week of the year and the current day of the year respectively which is different from the earlier result.

[Here, I’m not setting any date. The statement cal.set(2011, 11, 11); in the above code is commented out and the system is automatically retrieving the current date which is 2011-11-11].


In both the cases, the same date is used which is 2011-11-11 still the result obtained is different in both of the cases. Why?

  • 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-26T19:23:16+00:00Added an answer on May 26, 2026 at 7:23 pm

    The month value is 0-based. If you meant November, use:

    cal.set(2011, 10, 11);
    

    See the Calendar javadocs.

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

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have a class like this: public class Person { private String
Let us assume I have two classes: class Base{}; class Derived: public Base{}; none
Let's say I have the following code: Sub TestRangeLoop() Dim rng As Range Set
Let's say I have the following within my source code, and I want to
Let's look at the code below $SBK=0x1682CCD8 0x8A1A43EA 0xA532EEB6 0xECFE1D98 ./windows/nvflash/nvflash.exe --sbk 0x1682CCD8 0x8A1A43EA
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Let's assume i got this code: internal static bool WriteTransaction(string command) { using (SqlConnection
Let's say we have a class with an NSTimeInterval property: @interface MyClass : NSObject
Let's say we have the following mega-simple Python script: print Initializing.... a=10 print Variable

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.