java - 我的java代码计算给定日期的本周说法有什么问题

标签 java

计算给定日期的算法的伪代码 1753年以后的日期如下。 让 d 是一个月中的第几天(从 1 到 31), 米 是一个整数,表示 一年中的月份(其中 1 表示一月, 2 表示二月,依此类推), 和 y 表示年份。然后该算法按顺序执行以下步骤:

If m is less than 3
Add 12 to m and subtract one from y
End if
Set C to be the year of the century (e.g., 10 for the year 2010)
Set D to be the century (e.g., 20 for the year 2010)
Divide 13 * (m + 1) by 5 and call the quotient W
Divide C by 4 and call the quotient X
Divide D by 4 and call the quotient Y
Set Z to be W + X + Y + d + C - 2 * D
Divide Z by 7 and call the remainder day
If day is less than 0
Add 7 to day
End if

值(value) 天 然后给出星期几 0= 周六, 1= 周日,上 到 6= 星期五

到目前为止我的代码是:

public static String dayOfWeek( SimpleDate date ) {
        // TO BE COMPLETED
        int[] d = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
        int[] m = {1,2,3,4,5,6,7,8,9,10,11,12};
        int y = SimpleDate(int year);

        if (m < 3) {
            m + 12;
            y - 1;
        }
        C = SimpleDate(int year[2:3];
        D = SimpleDate(int year[0:1];
        W = 13 * (m + 1) / 5;
        X = C / 4;
        Y = D / 4;
        Z = W + X + Y + d + C - 2 * D;
        day = Z % 7;
        if (day < 0) {
            day + 7;
        }

我不知道如何设置 C 和 D 的年份以及开头。 另外,当我使用 m + 12 等代码时,我收到一条错误消息,指出 + 不是语句

最佳答案

如何使用java.util.Calendar并执行操作

calendar.get(Calendar.DAY_OF_WEEK);

关于java - 我的java代码计算给定日期的本周说法有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14969093/

相关文章:

java - Hibernate物化不存在的实体

java - 无法找出文件中的句子数

java - 安卓 : Start Activity after button animation

java - 在 JSP 中使用 Struts2 的 session

来自另一个类的 Java setText JLabel

java - 将字段转换为 HashMap

java - 为什么这个不确定的 jProgressBar 在这个简单的代码中不起作用?

java - 自定义 ListView 在 Fragment 中旋转时消失

java - 在 Android 中使用 RestTemplate 使用 https REST WebService

java - 代码重复与可读性