0

我需要您的帮助才能将当天的全名添加到此脚本中(例如星期一、星期二……等等……)。我找到了包含这个的脚本

nameDay = new Array('Domenica','Lunedi','Martedi','Mercoledi','Giovedi','Venerdi','Sabato');

(我是意大利人)

但我想使用以下脚本,因为它是服务器端并且它是跨浏览器兼容的。我只是想给它加上日子的名字。

这是我要编辑的脚本。谢谢

<script>
var data = new Date();
data.setTime(<? echo time()*1000; ?>);
function clock()
{

var hou = data.getHours();
var min = data.getMinutes();
var sec = data.getSeconds();
if(hou<10){ ora= "0"+ora;}
if(min<10){ min= "0"+min;}
if(sec<10){ sec= "0"+sec;}
document.getElementById('clock').innerHTML = data.getDate()+"/"+(data.getMonth()+1)+"/"+data.getFullYear()+" - "+hou+":"+min+":"+sec;
    data.setTime(data.getTime()+1000)
    setTimeout("clock();",1000);
}

</script><body onload="clock()">
<div id="clock"></div>
4

2 回答 2

1

data.getDay() 将为您提供日期索引。0 代表星期日,1 代表星期一,以此类推。

<script>
var nameOfDay = new Array('Domenica','Lunedi','Martedi','Mercoledi','Giovedi','Venerdi','Sabato');
var data = new Date();
data.setTime(<?php echo time() * 1000; ?>);
function clock()
{

var hou = data.getHours();
var min = data.getMinutes();
var sec = data.getSeconds();
if(hou<10){ hou= "0"+hou;}
if(min<10){ min= "0"+min;}
if(sec<10){ sec= "0"+sec;}

var dayIdx = data.getDay();
var day = nameOfDay[dayIdx];

document.getElementById('clock').innerHTML = day + " " + data.getDate()+"/"+(data.getMonth()+1)+"/"+data.getFullYear()+" - "+hou+":"+min+":"+sec;
    data.setTime(data.getTime()+1000)
    setTimeout("clock();",1000);
}

</script><body onload="clock()">
<div id="clock"></div>
于 2013-07-10T14:32:25.533 回答
0

作为w3schools, getDay() 方法将返回当天。

所以这是代码:

<script>
var data = new Date();
data.setTime(<?php echo time()*1000; ?>);
nameDay = new Array('Domenica','Lunedi','Martedi','Mercoledi','Giovedi','Venerdi','Sabato');
function clock()
{
    var hou = data.getHours();
    var min = data.getMinutes();
    var sec = data.getSeconds();
    var day = data.getDay();
    if(hou<10){ ora= "0"+ora;}
    if(min<10){ min= "0"+min;}
    if(sec<10){ sec= "0"+sec;}
    day = nameDay[day];
    document.getElementById('clock').innerHTML = data.getDate()+"/"+(data.getMonth()+1)+"/"+data.getFullYear()+" "+day+" - "+hou+":"+min+":"+sec;
    data.setTime(data.getTime()+1000)
    setTimeout("clock();",1000);
}

</script><body onload="clock()">
<div id="clock"></div>
于 2013-07-10T14:35:08.760 回答