java获取某年某月某日是星期几(极简方法)

package com.ttest2;

class test {
public int GetWeek(int y, int m, int d) {
if (m < 3) {
m += 12;
--y;
}
int w = (d + 1 + 2 * m + 3 * (m + 1) / 5 + y + (y >> 2) - y / 100 + y / 400) % 7;
return w;
}
}

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

test t = new test();

System.out.println(t.GetWeek(2016, 6, 3));
}
}

posted @ 2016-06-05 23:22  victorAii  阅读(1234)  评论(0编辑  收藏  举报