Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript for current date

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Well, in a new documanet I have the date appearing as I want with the following code:

</head>
<font face=&quot;arial&quot; size=&quot;1&quot; COLOR=&quot;#161616&quot;>
<center>
<SCRIPT LANGUAGE=&quot;JavaScript1.2&quot;>
var time=new Date();
var month=time.getMonth();
var date=time.getDate();
var year=time.getYear();
document.write(date + &quot; &quot; + (month+1) + &quot; &quot; + year);
</script>

It works in a newly created page, but when I try to add it to all pages in my website, it doesn't appear. I've tried setting &quot;padding&quot; etc. but it doesn't work. I also want to align it right not centre page - when I put right instead it just goes to the left. Any ideas of how to solve these - I'm really not sure where to put the code with all the other html code in my pages.
:(
 
Follow the two pieces of code. The first goes in between the
Code:
<head></head>
tags. The second bit goes where you want the date to appear. It can be wrapped for left right placement by putting the second half of the code like this:
Code:
<span align=&quot;left&quot;>code here</span>

thread256-223744 DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Sorry I don't know which bits of code you mean exactly. I can see the <head> and </head> tags at the top of the code for my page, but which code goes between there?

Basically, what is the first piece of code and what's the second piece of code, you're referring to exactly?

THX
 
This is the first that goes in between the head tags:

Code:
<script language=&quot;javascript&quot; type=&quot;text/javascript&quot;>
<!-- Hide From Oldies
today=new Date();

// Build an array initializer
function isnArray() {
    argnr=isnArray.arguments.length
    for (var i=0;i<argnr;i++) {
        this[i+1] = isnArray.arguments[i];
    }
}

// And months and day arrays
var isnMonths=new isnArray(&quot;01&quot;,&quot;02&quot;,&quot;03&quot;,&quot;04&quot;,&quot;05&quot;,&quot;06&quot;,&quot;07&quot;,&quot;08&quot;,&quot;09&quot;,&quot;10&quot;,&quot;11&quot;,&quot;12&quot;);
var isnDays= new isnArray(&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;,&quot;Sunday&quot;);
isnDays[0]=&quot;Sunday&quot;;

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}
</script>    
//  -->


This is the second that goes where you want the date to show. For example in a particular <td> tag or in the middle of a paragraph or wherever:
Code:
<script language=&quot;JavaScript&quot;>
    <!--Hide JavaScript

var thisyear = today.getYear(); // varies in JavaScript and JScript
 
document.write(isnMonths[today.getMonth()+1]+&quot; / &quot;+today.getDate()+&quot; / &quot;)

if (thisyear >= 2000) { // covers JScript post 2000
    document.write(thisyear);
    }
else { // covers JScript from 1900 thru 1999 and JavaScript until 3899
    document.write(1900 + thisyear);
    } // not handled: JScript pre 1900

// End hiding of script -->

You can use the FP Insert>Advanced>HTML Code to add the second part in page view mode.
DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top