如何在不使用内置日历日期包的情况下在java中打印日期

时间:2014-01-06 11:50:56

标签: java

在这个节目中,我平时大约一整天。 例如,通过输入1 1 2014我得到输出为星期三.. 但不是在闰年的例子,通过输入1 1 2000我得到周六的确切答案.. 但我得到的回答是1月2000日是星期一..任何人都可以解决这个问题......

Reference for Day of the date

//reference i made this program: http://easycalculation.com/funny/shortcuts/day.php
//gd = given date
//gm = given month
//gy = given year
//ym = year modulus (year % 100 to get last two digits)
//yp = year process (ym%4 to get remainder)
//wd = week days (0 for sunday, 1 for monday and so on...)
//d = day calculation (to get remainder from 0 to 6 .. which represents wd[0]
//for sunday so on)

import java.util.Scanner;
class dayof
{
public static void main(String arg[])
    {
    int gd,gm,gy,ym,yp,d;
    int[] m=new int[]{0,3,3,6,1,4,6,2,5,0,3,5};
    String[] wd=new String[]{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
    Scanner ip=new Scanner(System.in);
    System.out.println("Enter Date Month Year \"DD MM YYYY\"");
    gd=ip.nextInt();
    gm=ip.nextInt();
    gy=ip.nextInt();
    ym=gy%100;
    yp=ym%4;
    d=(gd+m[gm-1]+ym+yp+1)%7;
    System.out.print(wd[d]);
    }
}

0 个答案:

没有答案