title | date | draft | tags | categories | |||
---|---|---|---|---|---|---|---|
算法4 Java解答 1.2.12 |
2019-02-22 07:35:22 +0800 |
false |
|
|
Add a method dayOfTheWeek() to SmartDate that returns a String value Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, or Sunday, giving the appropriate day of the week for the date. You may assume that the date is in the 21st century.
- 可以根据公式计算
public static int dayOfTheWeek(int y, int m, int d){
int y0 = y - (14 - m) / 12;
int x = y0 + y0/4 - y0/100 + y0/400;
int m0 = m + 12 * ((14 - m) / 12) - 2;
int d0 = (d + x + (31*m0)/12) % 7;
return d0;
}
- 可以统计目前到0001-01-01有多少天,把那天当做anchor