Javascript Jscript在开发人员和测试机器上返回不同的(计算的)结果-使用相同的代码
好的,在我的开发机器上,我有以下代码: JScriptJavascript Jscript在开发人员和测试机器上返回不同的(计算的)结果-使用相同的代码,javascript,html,asp.net-mvc,date-arithmetic,Javascript,Html,Asp.net Mvc,Date Arithmetic,好的,在我的开发机器上,我有以下代码: JScript setInterval(function () { myTimer(); }, 1000); function myTimer() { var d = new Date(); var hrs = d.getHours(); var min = d.getMinutes(); var sec = d.getSeconds(); var dayOfWeek = d.getDay(); // L
setInterval(function () { myTimer(); }, 1000);
function myTimer() {
var d = new Date();
var hrs = d.getHours();
var min = d.getMinutes();
var sec = d.getSeconds();
var dayOfWeek = d.getDay();
// Let's do this logically.
// To get the number of victims so far today we need to know how many seconds have passed so far today.
var totalSeconds = sec + (min * 60) + (hrs * 3600); // Number of Seconds passed so far today.
// Now multiply that by 14 in accordance with Symantec's research.
var VictimsToday = totalSeconds * 14;
// To get the number of victims this week we need to multiply
// The number of seconds in a day by the number of full days and add the number of seconds of this partial day.
var TotalSecondsInADay = 86400; // According to Google.
var DaysSoFarThisWeek = dayOfWeek + 1; // Removes today as a partial day.
// We already know how many seconds are in this partial day = totalSeconds
// So our calculation is
var tsD = TotalSecondsInADay * DaysSoFarThisWeek;
var VictimsThisWeek = (totalSeconds + tsD) * 14;
// Now we get the Day of the Year remove today as a partial day and calculate
// Number of seconds a day by the number of complete days so far + todays partial day
var DOY = DayOfYear();
var tsY = DOY * totalSeconds;
var VictimsThisYear = (totalSeconds + tsY) * 14;
document.getElementById("FooterStatistics").innerHTML = Intl.NumberFormat().format(VictimsToday);
document.getElementById("FooterStatistics2").innerHTML = Intl.NumberFormat().format(VictimsThisWeek);
document.getElementById("FooterStatistics4").innerHTML = Intl.NumberFormat().format(VictimsThisYear);
}
function DayOfYear() {
var today = new Date();
var first = new Date(today.getFullYear(), 0, 1);
var theDay = Math.round(((today - first) / 1000 / 60 / 60 / 24) + 0.5, 0);
return theDay;
}
其中HTML为:
身体
现在,在Dev计算机上,DIV中返回的计算是:
但是,当我在W3T编辑器上运行此命令时:
我得到了一个完全不同的计算结果:
现在我知道,由于时区的不同,数字会有所不同——不应该不同的是实际的计算结果。Dev机器的第二个结果比第一个结果小,这是不应该的,第三个结果显然不是一个数字——根据TryIt编辑器中的结果,可以提供更合理的asnwers
这是怎么回事?在创建应用程序时,请继续使用
console.log()
检查值。这确实有助于理解未来正在发生的事情。虽然这不是调试的替代方案,但它很有帮助。您只能在您的代码即将投入使用时删除它们,或者您确信它可以正常工作并且可以很好地抽象
PS:避免使用
w3schools.com
。使用。好多了。我试过运行你的,但效果不错。是的,我知道它可以工作-但是它在开发机器上不工作。你确保开发机器上的代码没有任何印刷错误吗?它被复制和粘贴。所以没有错误。如果你加上这句话,作为答案——我会接受的——应该仔细看看;但是发现了问题并解决了-指向了一个旧版本的脚本。
<div id="FooterStatistics"></div>
<div id="FooterStatistics2"></div>
<div id="FooterStatistics4"></div>