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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Format

Status
Not open for further replies.

cdumigan

MIS
Feb 5, 2002
16
IE
Hi,
I'm just wondering what the correct format is for writing dates in JavaScript. Is it, for example: Thu, 09-Jan-90 00:00:01 GMT?
Thanks,
Conor
 
There are many ways to write the date using JS...
There's isn't one format (or a right and wrong), you would use the .getDate, getMonth, getFullYear syntax...
This is what I use in my website:

<SCRIPT>
var mydate=new Date()
var theYear=mydate.getFullYear()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym=&quot;0&quot;+daym
var dayarray=new Array(&quot;Sunday&quot;,&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;)
var montharray=new Array(&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;)
document.write(&quot;<font face='Geneva, Arial, Helvetica, san-serif'><h6>&quot;+dayarray[day]+&quot;<br>&quot;+montharray[month]+&quot;/&quot;+daym+&quot;/&quot;+theYear+&quot;</h6></font>&quot;)
</SCRIPT>

The document.write method displays the date on the browser in any location. I have not failed; I merely found 100,000 different ways of not succeding...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top