我尝试找出 diff 和 currentDate.getTimezoneOffset 之间的差异。 我已经检查过它们都是数字,但它显示的是NaN。
这是 js代码:
$(document).ready(function() {
// Grab the current date
var currentDate = new Date();
// Set some date in the future. In this case, it's always Jan 1
var futureDate = new Date(currentDate.getFullYear() + 0, 8, 4);
// Calculate the difference in seconds between the future and current date
var diff = futureDate.getTime() / 1000 - currentDate.getTime() / 1000;
console.log(typeof parseInt(currentDate.getTimezoneOffset()))
console.log(typeof diff)
console.log(parseInt(currentDate.getTimezoneOffset()))
console.log(diff)
console.log(diff - parseInt(currentDate.getTimezoneOffset))
});
任何人都可以向我解释为什么会发生这种情况以及如何解决它?
答案 0 :(得分:3)
这里的语法错误:
console.log(typeof parseInt(currentDate.getTimezoneOffset))
应该是
console.log(typeof parseInt(currentDate.getTimezoneOffset()))
^^ missing brackets here