PDA

View Full Version : need help with this peace of code


Dan S
04-03-2002, 11:54 AM
How to get this code to print Apr 03 instead of Apr 3? <br /><br /></font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: fixed;"> <br />&lt;script&gt;<br />function update()<br />{ var months=new Array(13); months[1]=&quot;Jan&quot;; months[2]=&quot;Feb&quot;; months[3]=&quot;Mar&quot;; months[4]=&quot;Apr&quot;; months[5]=&quot;May&quot;; months[6]=&quot;Jun&quot;; months[7]=&quot;Jul&quot;; months[8]=&quot;Aug&quot;; months[9]=&quot;Sep&quot;; months[10]=&quot;Oct&quot;; months[11]=&quot;Nov&quot;; months[12]=&quot;Dec&quot;; var time=new Date(); var lmonth=months[time.getMonth() + 1]; var date=time.getDate(); var year=time.getYear(); if ((navigator.appName == &quot;Microsoft Internet Explorer&quot;) &amp;&amp; (year &lt; 2000)) year=&quot;19&quot; + year;if (navigator.appName == &quot;Netscape&quot;)year=1900 + year; document.write(lmonth + &quot; &quot;); document.write(date + &quot; &quot;); }<br />&lt;/script&gt;</pre><hr /></blockquote><font size="2" face="Verdana, Arial">Thanks!

Pinhead
04-03-2002, 01:19 PM
Replace<br /><br />document.write(date + " ")<br /><br />with<br /><br />document.write((date&lt;10?"0":"") + date + " ")<br /><br />in your code snippet.

Clocka
04-03-2002, 01:23 PM
Not really a better way....<br />just a fix....<br /> <img border="0" title="" alt="[Big Grin]" src="biggrin.gif" /> <br /></font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: fixed;"> &lt;script&gt;function update(){ var months=new Array(13); months[1]=&quot;Jan&quot;; months[2]=&quot;Feb&quot;; months[3]=&quot;Mar&quot;; months[4]=&quot;Apr&quot;; months[5]=&quot;May&quot;; months[6]=&quot;Jun&quot;; months[7]=&quot;Jul&quot;; months[8]=&quot;Aug&quot;; months[9]=&quot;Sep&quot;; months[10]=&quot;Oct&quot;; months[11]=&quot;Nov&quot;; months[12]=&quot;Dec&quot;; var time=new Date(); var lmonth=months[time.getMonth() + 1]; var date=time.getDate(); var year=time.getYear(); if ((navigator.appName == &quot;Microsoft Internet Explorer&quot;) &amp;&amp; (year &lt; 2000)) year=&quot;19&quot; + year;if (navigator.appName == &quot;Netscape&quot;)year=1900 + year; document.write(lmonth + &quot; &quot;); if (date &lt; 10) document.write(&quot;0&quot;); document.write(date + &quot; &quot;); }&lt;/script&gt; </pre><hr /></blockquote><font size="2" face="Verdana, Arial">just added </font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: fixed;">if (date &lt; 10) document.write(&quot;0&quot;);<br /> </pre><hr /></blockquote><font size="2" face="Verdana, Arial"><img border="0" title="" alt="[Big Grin]" src="biggrin.gif" />

Dan S
04-03-2002, 01:40 PM
Thanks guys <img border="0" title="" alt="[Smile]" src="smile.gif" />