Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1007 Bytes

Ex_1_2_12.md

File metadata and controls

42 lines (29 loc) · 1007 Bytes
title date draft tags categories
算法4 Java解答 1.2.12
2019-02-22 07:35:22 +0800
false
JAVA
技术
归档

1.2.12

问题:

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.

分析:

  1. 可以根据公式计算
    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;
    }

2019-06-22-001

  1. 可以统计目前到0001-01-01有多少天,把那天当做anchor

参考:

doomsday

utube_vedio