Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateUtil 日期工具类 发现一个错误! #584

Open
chorar opened this issue Feb 7, 2018 · 0 comments
Open

DateUtil 日期工具类 发现一个错误! #584

chorar opened this issue Feb 7, 2018 · 0 comments

Comments

@chorar
Copy link

chorar commented Feb 7, 2018

public static int getMonthLength(@NotNull final Date date) {
    int year = get(date, Calendar.YEAR);
    int month = get(date, Calendar.MONTH);
    return getMonthLength(year, month);
}

public static int getMonthLength(int year, int month) {
    if ((month < 1) || (month > 12)) {
        throw new IllegalArgumentException("Invalid month: " + month);
    }
    if (month == 2) {
        return isLeapYear(year) ? 29 : 28;
    }
    return MONTH_LENGTH[month];
}

因为
  int month = get(date, Calendar.MONTH); 获取的月份应该是 0-11 之间
所以
  结果是错误的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant