countdown.js给出不正确的时差

时间:2015-02-05 10:41:26

标签: javascript jquery

我正在使用https://bitbucket.org/mckamey/countdown.js来设置fromDatetoDate之间的倒计时文字。以下是我的代码段

var fromDate = new Date(2015, 01, 01);
var toDate = new Date(2015, 01, 02);
var countDown = countdown(fromDate, toDate).toString();
console.log(fromDate);
console.log(toDate);
console.log(countDown);

我得到以下输出

Sat Feb 01 2015 00:00:00 GMT+0530 (IST)
Sun Feb 02 2015 00:00:00 GMT+0530 (IST)
-1 years, 11 months, and 30 days.

我还试图像这样构建fromDatetoDate

var fromDate = new Date("February 01, 2015 00:00:00");

但我得到了相同的负值。我做错了什么或这是countdown.js本身的问题吗?

1 个答案:

答案 0 :(得分:1)

我无法准确找到问题但是当我在本地使用他们的代码时它能正常工作我得到了正确的结果

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="countdown.js"></script>

</head>
<body>
    <script>
var fromDate = new Date(2015, 01, 01);
var toDate = new Date(2015, 01, 02);
var countDown = countdown(fromDate, toDate).toString();
console.log(fromDate);
console.log(toDate);
console.log(countDown);
</script>
</body>
</html>

here复制countdown.js代码并将其保存在本地。

结果我得到的是

Date {Sun Feb 01 2015 00:00:00 GMT+0530 (India Standard Time)}
Date {Mon Feb 02 2015 00:00:00 GMT+0530 (India Standard Time)}
1 day