Learn how to display Date Amp Time using JavaScript


0

With the help of the snippet in this article, you will learn how to display data and time using JavaScript

<html>
<head>
<script language="javascript">
var a,b,c,d,e,f;
var d = new Date();
a = d.getMonth()+1;

e = d.getDay()+1;
if(e ==1) {
f = "Sunday"
}
else if(e ==2) {
f = "Monday"
}
else if(e ==3) {
f = "Tuesday"
}
else if(e ==4) {
f = "Wednesday"
}
else if(e ==5) {
f = "Thursday"
}
else if(e ==6) {
f = "Friday"
}
else if(e ==7) {
f = "Saturday"
}


if (a==1) {
b = "January"
}
else if(a==2) {
b = "February"
}
else if(a==3) {
b = "March"
}
else if(a==4) {
b = "April"
}
else if(a==5) {
b = "May"
}
else if(a==6) {
b = "June"
}
else if(a==7) {
b = "July"
}
else if(a==8) {
b = "August"
}
else if(a==9) {
b = "September"
}
else if(a==10) {
b = "October"
}
else if(a==11) {
b = "November"
}
else if(a==12) {
b = "December"
}

c = d.getDate();
d = d.getYear();
document.write(f+" " +b +" " +c + ", " +d)
</script>
</head>
<body>
</body>
</html>

Like it? Share with your friends!

0

What's Your Reaction?

hate hate
0
hate
confused confused
0
confused
fail fail
0
fail
fun fun
0
fun
geeky geeky
0
geeky
love love
0
love
lol lol
0
lol
omg omg
0
omg
win win
0
win
Anand Narayanaswamy
Anand Narayanaswamy is the editor-in-chief of Learnxpress. He was a Microsoft Most Valuable Professional (MVP) for a period of 9 years. He is a ASPInsider based in Trivandrum, Kerala State, India. Anand is the author of Community Server Quickly published by Packt Publishing.

One Comment

Your email address will not be published. Required fields are marked *

  1. Hey, I found this article while searching for help with JavaScript. I have recently changed browsers from Opera to Internet Explorer 7. Just recently I seem to have a issue with loading JavaScript. Everytime I browse website that needs Javascript, my browser does not load and I get a “runtime error javascript.JSException: Unknown name”. I cannot seem to find out how to fix the problem. Any help is greatly appreciated! Thanks