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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:23:53+00:00 2026-05-23T21:23:53+00:00

I am writing a program to display the Day for the given date. (E.g.

  • 0

I am writing a program to display the Day for the given date. (E.g. Thursday for 1/1/1970.)
While attempting that I have some problems.

This is my program.

/*Concept: 
 The noOfDays variable will count the no of days since 01/01/0001. And this will be Day one(1). E.g 
 noOfDays = 365 for 01/12/0001 and noOfDays = 731 for 01/01/0003 and so on....
 Since I taken Monday as 01/01/0001,the day of the specific date can be achieved by switching(noOfDays%7)
 E.g. 365 % 7 = 1. So, the 365th day is monday...
*/

import java.util.Scanner;
class DayDisplayer
{
    long noOfDays;
    int month;
    int days;
    int year;
    Scanner scan;
    int countYear;
    int countMonth;

    DayDisplayer()
    {
        scan = new Scanner(System.in);
        noOfDays = 0;
        System.out.println("Enter the date please");

        days = scan.nextInt();
        month = scan.nextInt();
        year = scan.nextInt();

        System.out.println("Your Date is:  "+days+"/"+month+"/"+year);



    }

    boolean leapYearCheck(int year)
    {
        if( ((year%100 == 0) && (year%400 != 0)) || (year%4 != 0) )  // when it is divisible by 100 and not by 400.  
            return false;
        else
            return true;

    }

    boolean isThere31Days()
    {
        if ( ( (countMonth >> 3) ^ (countMonth & 1) ) == 1 ) 
            return true;
        else 
            return false;

    }

    void getDaysThatInDays()    
    {
        noOfDays += days;
    }

    void getDaysThatInMonth()
    {

        countMonth = 1;

        while(countMonth<month)
        {
            if( countMonth == 2 )
                if( leapYearCheck(year) == true)
                    noOfDays += 29;
                else 
                    noOfDays += 28;
            else
               if ( isThere31Days()) 
                   noOfDays += 31;
               else 
                   noOfDays += 30;

            countMonth++;
        }                   



    }

    void getDaysThatInYear()
    {
        countYear = 1;

        while(countYear<year)
        {
            if( leapYearCheck(countYear)== true )  
                    noOfDays += 366; 
                else 
                    noOfDays += 365;

            countYear ++;
        }
    }

    void noOfDaysAndDayName()
    {
        System.out.println("The noOfDays is"+noOfDays);

        System.out.println("And Your Day is :"); 

        int day;

        day = (int)(noOfDays%7);
        switch(day)
        {

        case 0:
            System.out.println("Sunday");
            break;
        case 1:
            System.out.println("Monday");
            break;
        case 2:
            System.out.println("Tuesday");
            break; 
        case 3:
            System.out.println("Wednesday");
            break;
        case 4:
            System.out.println("Thursday");
            break;
        case 5:
            System.out.println("Friday");
            break;
        case 6:
            System.out.println("Saturday");
            break;
        }

    }

}// end of MonthToDate class

public class Main
{
    public static void main(String args[])
    {

        DayDisplayer  dd= new DayDisplayer();

        dd.getDaysThatInYear();
        dd.getDaysThatInMonth();
        dd.getDaysThatInDays();

        dd.noOfDaysAndDayName();


    }



}

In this code ,when I take 01/01/0001 as Monday and calculated the other days. And I am getting correct answers.

But In http://www.timeanddate.com website they took 01/01/0001 as Saturday.
But still for the other recent dates (say 17/7/2011) they are giving the correct answer (as Sunday).

I could guess these lags are due to the migration of Julier system to Gregorian system.

But I have a doubt whether my approach of calculating the Days from 0001 year is correct or not?

Also I have a doubt about whether to take 01/01/0001 date is Monday or Saturday.
(And If I took Saturday as my first day, I am getting wrong answers.)

someone please explain.

Thanks in advance.

  • 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-23T21:23:54+00:00Added an answer on May 23, 2026 at 9:23 pm

    One problem could be highlighted by an off-by-one error your opening comment:

    The noOfDays variable will count the no of days since 01/01/0001. E.g 
    noOfDays = 365 for 01/12/0001 and noOfDays = 731 for 01/01/0003 and so on.
    

    That says that 0001-01-01 will be day 0 (0 days since the reference date), which in turn means that 0001-12-31 on your proleptic Gregorian calendar will be 364, not 365.

    You can adjust this in either of two ways:

    • Define that 0001-01-01 will be day 1 (whereupon the rest of the quoted fragment of comment is correct).
    • Change the comment values to 364 and 730.

    Another problem with reverse engineering dates back that far is understanding the ‘proleptic’ Gregorian calendar. The term strictly means ‘the representation of a thing as existing before it actually does or did so’, and applies forward, but the term is also used in calendrical calculations to refer to applying the present rules backwards in time. The issue at hand is that the Gregorian calendar with its rules for leap years (divisible by 400, or divisible by 4 but not divisible by 100) did not exist in year 1. And the question is: did the web sites you referred to compensate for the switch between the Julian calendar and the Gregorian? (Underlying that are a lot of complications; the calendar was exceptionally volatile, even in the Roman Empire, between about 55 BCE and 200 CE.)


    An excellent book for considering matters of date is Calendrical Calculations.

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

Sidebar

Related Questions

This is a program I'm writing that's supposed to display some text in a
Im writing a program that should read input via stdin, so I have the
I'm writing a program that, among other things, needs to display a context menu
I am writing a simple digital image processing program. To do this I have
I'm writing a program that sends an email out at a client's specific local
If you are writing a program that is executable from the command line, you
I'm writing a program that uses SetWindowRgn to make transparent holes in a window
I am writing a program in Python that will act as a server and
I'm writing a program that contains a generational garbage collector. There are just two
I am writing a program that will draw a solid along the curve of

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.