is it possible to display the date using javascript e.g. 12th March 2008 NOT 12th March 2008 <time/time zone> ?
show date using javascript
Started by cinek, Mar 12 2008 11:00 AM
7 replies to this topic
#1
Posted 12 March 2008 - 11:00 AM
|
|
|
#2
Posted 13 March 2008 - 07:55 AM
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.
#3
Posted 13 March 2008 - 12:19 PM
Um what actually do you want to do?
this should work :)
<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
Posted 13 March 2008 - 02:55 PM
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)
.... 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
Posted 13 March 2008 - 04:39 PM
Put this in a javascript file called date.js
and in your html file put this in your head:
and in your body
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
Posted 14 March 2008 - 10:18 AM
thanks :)
#7
Guest_Jordan_*
Posted 15 March 2008 - 06:43 AM
Guest_Jordan_*
Nice work chili5, +rep given.
#8
Posted 16 March 2008 - 05:14 AM
Thanks Jordan :D


Sign In
Create Account


Back to top









