0

I need your help to add to this script the full name of the day (like Monday, Tuesday... etc...). I found scripts containing this

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

(I'm italian)

But I want to use the following script because is server side and it's cross browser compatible. I just want to add to it the name of the days.

This is the script that I want to edit. Thank you

<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>
2
  • That script is NOT server side. You're getting the time from the server, but that's it. It would be much simpler to do in pure PHP. Commented Jul 10, 2013 at 14:31
  • @Ben Is it a live clock in pure php? Commented Jul 10, 2013 at 14:41

2 Answers 2

1

data.getDay() will give you the day index. 0 will be Sunday, 1 will be Monday and so forth.

<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>
Sign up to request clarification or add additional context in comments.

Comments

0

as w3schools, getDay() method will return the day.

so this is the code:

<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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.