Reply
Help changing date & time javascript to just date...
Old 06-06-2006, 09:26 PM Help changing date & time javascript to just date...
Skilled Talker

Posts: 68
Hi there, I have the following code...

<script language="JavaScript" type="text/javascript">
<!-- hide from old browsers
var curDate = new Date()
document.write(curDate.toLocaleString())
//-->
</script>


Which outputs the following...

Wednesday, 7 June 2006 11:25:04 AM

Is it possible to change the code so that it outputs just the date...

Eg: Wednesday, 7 June 2006

Mally
malhyp is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 06-06-2006, 09:47 PM Re: Help changing date & time javascript to just date...
frofi's Avatar
Extreme Talker

Posts: 215
Location: London
This should work:
<script language="JavaScript" type="text/javascript">

var d=new Date();
var monthname=new Array("January","February","March","April","May"," June","July","August","September","October","Novem ber","December");
var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();

</script>
frofi is offline
Reply With Quote
View Public Profile
 
Old 06-06-2006, 09:55 PM Re: Help changing date & time javascript to just date...
frofi's Avatar
Extreme Talker

Posts: 215
Location: London
Then put this code exactly where you want the date to show.

<script language="JavaScript" type="text/javascript">
document.write(TODAY); </script>
frofi is offline
Reply With Quote
View Public Profile
 
Old 06-06-2006, 10:15 PM Re: Help changing date & time javascript to just date...
frofi's Avatar
Extreme Talker

Posts: 215
Location: London
Oops. Sorry I forgot you want the day as well

Here is the code:

<SCRIPT Language="JavaScript">
<!-- hide from old browsers
function GetDay(intDay){
var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday")
return DayArray[intDay]
}

function GetMonth(intMonth){
var MonthArray = new Array("January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December")
return MonthArray[intMonth]
}
function getDateStrWithDOW(){
var today = new Date()
var year = today.getYear()
if(year<1000) year+=1900
var todayStr = GetDay(today.getDay()) + ", "
todayStr += GetMonth(today.getMonth()) + " " + today.getDate()
todayStr += ", " + year
return todayStr
}
//-->
</SCRIPT>

And here is how you implement it:

<SCRIPT Language="JavaScript">
<!-- hide from old browsers
document.write(getDateStrWithDOW())
//-->
</SCRIPT>

These things are easy to find on the WEB.
http://www.javascriptmall.com/jsc/jsC4Udate.htm
frofi is offline
Reply With Quote
View Public Profile
 
Old 06-09-2006, 05:33 AM Re: Help changing date & time javascript to just date...
scottfree's Avatar
Extreme Talker

Posts: 234
Location: Hamburg
You could also try this:

function getDate()
{
var d, s = "Today's date is: ";
d = new Date();
s += (d.getMonth() + 1) + "/";
s += d.getDate() + "/";
s += d.getYear();
return(s);
}
__________________
I think, therefore I am..... I think.

Last edited by scottfree : 06-09-2006 at 05:34 AM.
scottfree is offline
Reply With Quote
View Public Profile Visit scottfree's homepage!
 
Old 06-09-2006, 06:33 AM Re: Help changing date & time javascript to just date...
Skilled Talker

Posts: 68
Thanks, they were all good.
malhyp is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help changing date & time javascript to just date...
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13487 seconds with 12 queries