Widgetized Section

Go to Admin » Appearance » Widgets » and move Gabfire Widget: Social into that MastheadOverlay zone

Learn how to display Date Amp Time using JavaScript

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

<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">&lt;</span><span style="color: #800000">html</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">head</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">script</span> <span style="color: #ff0000">language</span>=<span style="color: #0000ff">&quot;javascript&quot;</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">var</span> a,b,c,d,e,f;
<span style="color: #0000ff">var</span> d = <span style="color: #0000ff">new</span> <span style="color: #0000ff">Date</span>();
a = d.getMonth()+1;

e = d.getDay()+1;
<span style="color: #0000ff">if</span>(e ==1) {
f = &quot;<span style="color: #8b0000">Sunday</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(e ==2) {
f = &quot;<span style="color: #8b0000">Monday</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(e ==3) {
f = &quot;<span style="color: #8b0000">Tuesday</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(e ==4) {
f = &quot;<span style="color: #8b0000">Wednesday</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(e ==5) {
f = &quot;<span style="color: #8b0000">Thursday</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(e ==6) {
f = &quot;<span style="color: #8b0000">Friday</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(e ==7) {
f = &quot;<span style="color: #8b0000">Saturday</span>&quot;
}


<span style="color: #0000ff">if</span> (a==1) {
b = &quot;<span style="color: #8b0000">January</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(a==2) {
b = &quot;<span style="color: #8b0000">February</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(a==3) {
b = &quot;<span style="color: #8b0000">March</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(a==4) {
b = &quot;<span style="color: #8b0000">April</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(a==5) {
b = &quot;<span style="color: #8b0000">May</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(a==6) {
b = &quot;<span style="color: #8b0000">June</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(a==7) {
b = &quot;<span style="color: #8b0000">July</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(a==8) {
b = &quot;<span style="color: #8b0000">August</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(a==9) {
b = &quot;<span style="color: #8b0000">September</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(a==10) {
b = &quot;<span style="color: #8b0000">October</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(a==11) {
b = &quot;<span style="color: #8b0000">November</span>&quot;
}
<span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span>(a==12) {
b = &quot;<span style="color: #8b0000">December</span>&quot;
}

c = d.getDate();
d = d.getYear();
<span style="color: #0000ff">document</span>.write(f+&quot;<span style="color: #8b0000"> </span>&quot; +b +&quot;<span style="color: #8b0000"> </span>&quot; +c + &quot;<span style="color: #8b0000">, </span>&quot; +d)
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">script</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">head</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">body</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">body</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">html</span><span style="color: #0000ff">&gt;</span>

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
Posted by on March 22, 2009. Filed under Development,Web Development. You can follow any responses to this entry through the RSS 2.0. You can leave a response or trackback to this entry

One Response to Learn how to display Date Amp Time using JavaScript

  1. Tegan Sandine Reply

    March 4, 2010 at 8:41 pm

    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

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>