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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:44:49+00:00 2026-05-30T17:44:49+00:00

I am using Calendar Class in my android app to calulate day of year

  • 0

I am using Calendar Class in my android app to calulate day of year of a date and then do some comparison with current day of year. Here is the code I use :

Date now=new Date();
Calendar ca1 = Calendar.getInstance();
        ca1.set(now.getYear(), now.getMonth(), now.getDate());
        int nowC=ca1.get(Calendar.DAY_OF_YEAR);

//Date arg0=say,get from user
        Calendar ca2 = Calendar.getInstance();
        ca2.set(arg0.GetBirthDay().getYear(),arg0.GetBirthDay().getMonth(),arg0.GetBirthDay().getDate());
        int d1C=ca2.get(Calendar.DAY_OF_YEAR);

I debug my application and I see the following value for current day :
Fri Mar 02 14:18:33 Asia/Tehran 2012

and for arg0:
Fri Mar 02 00:00:00 Asia/Tehran 1979

And ‘nowC’ got 62, and ‘d1C’ got 61.

I expect them to be equal cause both of them has same month and day, also If I use DateTime class of joda package, as below, I get the same results:

int ndy=dtnow.getDayOfYear();
int d1dy=dt1.getDayOfYear(); 

Why it is happening ?

  • 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-30T17:44:50+00:00Added an answer on May 30, 2026 at 5:44 pm

    2012 was a leap year, 1979 was not. There is an extra day before March 2nd this year – so both APIs are giving you the right answer!

    I suspect you want to compare both the month and day-of-month, to get the semantics you are expecting.

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

Sidebar

Related Questions

I am using Calendar class to obtain the current date and time. Then I
I'm using calendar_helper with success using this code: <%= calendar({:year => Date.today.year, :month =>
How can I display the time in the current app locale using Calendar? For
Well am using eclipse to make an android app which accesses google calendar API
I am using a jQuery Class plugin as so : jQuery(document).ready(function($) { window.SSK.calendar =
In my rails app, I am using calendar helper cell.innerHTML = '<%= calendar_for('start_date')%>'; The
I am using ajax calendar extender for 'From date' and 'To date' text box,
I m Using a calendar.js file to implement calendar in my App. Actually this
I'm using jcal2 calendar for choosing date from calender. It working when i'm using
I'm using a GridView in my Android app. Everything works perfectly on my phone,

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.