Jump to content

show date using javascript

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
cinek

cinek

    Newbie

  • Members
  • PipPip
  • 13 posts
is it possible to display the date using javascript e.g. 12th March 2008 NOT 12th March 2008 <time/time zone> ?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I'm not clear on what you're asking, since you listed the same format both times. There are a variety of options for handling date formatting/display, however.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Um what actually do you want to do?


    <script language="javascript">  

    var theMonths = new 


Array("January","February","March","April","May","June","July","August","September","Octo


ber","November","December");  

    dt = new Date();  

    dy = dt.getDate()+"th ";  

    mo = dt.getMonth();  

    yr = " "+dt.getFullYear();  

  document.write(dy+theMonths[mo]+yr);  

    

 </script>  


this should work :)

#4
cinek

cinek

    Newbie

  • Members
  • PipPip
  • 13 posts
i want to display a date using javascript (Only date)

.... thx for the code, I don't really want to add it to my index.html page, is there any way to import it to the index page? (save as *.js)

#5
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Put this in a javascript file called date.js


 var theMonths = new 


Array("January","February","March","April","May","June","July","August","September","Octo


ber","November","December");  

    dt = new Date();  

     function getLetter(n) {  

     if(n == 1 || n == 21 || n == 31) {  

         return "st";  

     } else if (n == 2 || n == 22) {  

         return "nd";  

     } else if (n == 3 || n == 23) {  

        return "rd";       }  

    return "th";  

}  

dy = dt.getDate();  

dy = dy + getLetter(dy) + " "; 

    mo = dt.getMonth();  

    yr = " "+dt.getFullYear(); 


and in your html file put this in your head:


<script src="date.js"></script>


and in your body


<script language="javascript">

document.write(dy+theMonths[mo]+yr);  

</script>



#6
cinek

cinek

    Newbie

  • Members
  • PipPip
  • 13 posts
thanks :)

#7
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Nice work chili5, +rep given.

#8
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Thanks Jordan :D