October 2nd, 2012, 01:28 PM
-
How to display date with javascript coding?
Hi there,
I am new on javascript section. Just have started to learn javascript. I am trying to coding to show date and day......
here is the code I have created. It is showing only Wednesday when I am refreshing browser.
Is there any wrong I have made? will you check please
<html>
<head><title>Date Select</title>
</head>
<body>
<script type="text/javascript">
var date=new Date();
var day=date.getDay();
if (day==0)
{
window.document.write("Sunday");
}
else if (day==1)
{
window.document.write("Monday");
}
else if (day==2)
{
window.document.write("Tuesday");
}
else if (day==3)
{
window.document.write("Wednesday");
}
else if (day==4)
{
window.document.write("Thursday");
}
else if (day==5)
{
window.document.write("Friday");
}
else if (day==6)
{
window.document.write("Saturday");
}
</script>
</body>
</html>
I am waiting for your reply
Thanks in advance
October 2nd, 2012, 01:39 PM
-
What browser are you using; because I tested in IE, FF, and Chrome and they all show Tuesday?
October 2nd, 2012, 02:29 PM
-
Originally Posted by web_loone08
What browser are you using; because I tested in IE, FF, and Chrome and they all show Tuesday?
I am using firefox 10.0.2 version and it is showing Wednesday.
October 2nd, 2012, 04:16 PM
-
Well I tested in the latest version of FF, which is 15.0.1 and it displays Tuesday. You might want to check the date on your computer and see if it is set to Wednesday. Unless you have some more JS somewhere, that would be changing the day variable; then I do not know what the explanation would be.
October 4th, 2012, 03:27 AM
-
hi,
I just checked using chrome, firefox 15.0.1 and IE8, and they all display Thursday.
I like you am new to JavaScript, but i think this code is all good.
As suggested above you may want to test the date on your computer.
Regards
MG