Javascript中getDay的问题
嗨,这看起来很简单,但不起作用!我试着取两个历元数,在循环中计算当天的星期几。我需要这个,因为我不想计算周末的天数(即0或6天) 为什么每个时代我总是得到“6”?我的时代价值观有什么问题吗?注意,这是5天,因此每天的长度是86400 我将代码复制到此页面以进行测试: 在Javascript中getDay的问题,javascript,Javascript,嗨,这看起来很简单,但不起作用!我试着取两个历元数,在循环中计算当天的星期几。我需要这个,因为我不想计算周末的天数(即0或6天) 为什么每个时代我总是得到“6”?我的时代价值观有什么问题吗?注意,这是5天,因此每天的长度是86400 我将代码复制到此页面以进行测试: 在新日期(x)中,x需要采用unixEpoch格式(毫秒)-或。要解决您的问题,只需将所有值乘以1000: window.onload=function(){ var一天=86400000; 风险值天数=0; var currDa
新日期(x)
中,x
需要采用unixEpoch格式(毫秒)-或。要解决您的问题,只需将所有值乘以1000
:
window.onload=function(){
var一天=86400000;
风险值天数=0;
var currDay=0;
//var d=新日期();
//获取Epoch中的开始时间
var DAYDAY=1425531600000//来自用户选择
var endTime=1425960000000
//虽然我们的白天还不到结束时间,
//把日子循环一遍,数一数。
while(白天<结束时间){
//提前一天
日间=日间+一天;
document.body.insertAdjacentHTML('beforeed','out:“+day+”
”)
//把新纪元变成日期
var d=新日期(白天);
document.body.insertAdjacentHTML('beforeed',“out:”+d.getDay()+“
”)
}
}
Wow!谢谢我没有看到那一个。。哈哈。我欠你的!
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display todays day of the week.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var oneDay = 86400;
var days = 0;
var currDay = 0;
//var d = new Date();
// get the start time in Epoch
var dayTime = 1425531600 //from the user selection
var endTime = 1425960000
//while our dayTime is less than the end time,
//loop through the days and count them.
while (dayTime < endTime) {
// advance one day
dayTime = dayTime + oneDay;
document.write("out:"+dayTime+"<br>")
//turn the new time in Epoch into a date
var d = new Date(dayTime);
document.write("out:"+d.getDay()+"<br>")
}
}
</script>
</body>
</html>
out:1425618000
out:6
out:1425704400
out:6
out:1425790800
out:6
out:1425877200
out:6
out:1425963600
out:6