Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

function getTime()月份好像需要-1 #27

Open
LeBronlyou opened this issue Sep 29, 2017 · 1 comment
Open

function getTime()月份好像需要-1 #27

LeBronlyou opened this issue Sep 29, 2017 · 1 comment

Comments

@LeBronlyou
Copy link

function getTime()月份好像需要-1

@sAMs126
Copy link

sAMs126 commented Jan 4, 2020

javascript 的日期函数
new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]]);
其中 monthIndex 是从零开始计算的,所以 0 代表一月,11 代表十二月份。

Integer value representing the month, beginning with 0 for January to 11 for December.
from MDN

因此 getTime 方法应该修改为以下内容:

    function getTime(year, month, date) {
        if (year === undefined || month === undefined || date === undefined) return null;
-       return new Date(year, month, date, 23, 59, 59).getTime();
+       return new Date(year, month - 1, date, 23, 59, 59).getTime();
    }

这个错误 issue-233067893 也是因此而引起的。

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

No branches or pull requests

2 participants