...

View Full Version : Date and Time script including...



sciguyryan
10-19-2003, 12:35 PM
St, ND, Rd and TH with the date code E.G. 1st. Day Name included, Month Name included and A.M. or P.M. included.

Code mod also needed - How can I add a 0 to the start of the minutes if they are below 10 of that it wil display 12:07 instead of 12:7? - Please dont move this code as I have postd a script I just need a modification.

And, please tell me what you think or modifications I can make :)



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!--
var ampm = "a.m."
var mydate = new Date()
var monthday = mydate.getDate()
if (monthday == 4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||24||25||26||27||28||29||30)
{
var monthday = monthday + "<SUP>th</SUP>";
}
else if (monthday == 1||21||31)
{
var monthday = monthday + "<SUP>st</SUP>";
}
else if (monthday == 2||22)
{
var monthday = monthday + "<SUP>nd</SUP>";
}
else if (monthday == 3||23)
{
var monthday = monthday + "<SUP>rd</SUP>";
}
var month = mydate.getMonth()
if (month == 0)
{
var month = "January";
}
else if (month == 1)
{
var month = "Febuary";
}
else if (month == 2)
{
var month = "March";
}
else if (month == 3)
{
var month = "April";
}
else if (month == 4)
{
var month = "May";
}
else if (month == 5)
{
var month = "June";
}
else if (month == 6)
{
var month = "July";
}
else if (month == 7)
{
var month = "August";
}
else if (month == 8)
{
var month = "September";
}
else if (month == 9)
{
var month = "October";
}
else if (month == 10)
{
var month = "November";
}
else if (month == 11)
{
var month = "December";
}
var day = mydate.getDay()
if (day == 1)
{
var day = "Monday";
}
else if (day == 2)
{
var day = "Tuesday";
}
else if (day == 3)
{
var day = "Wednesday";
}
else if (day == 4)
{
var day = "Thursday";
}
else if (day == 5)
{
var day = "Friday";
}
else if (day == 6)
{
var day = "Saturday";
}
else if (day == 0)
{
var day = "Sunday";
}
var year = mydate.getYear()
var hours = mydate.getHours()
if (hours >= 12)
{
hours = hours - 12;
ampm = "p.m."
}
if (hours == 0)
{
hours = 12;
}
var minutes = mydate.getMinutes()
document.write("The Time is: " + hours + ":" + minutes +" " + ampm)
document.write("<BR>" + "The full date is: "+ day +", " + month + " the " + monthday + "&nbsp;" + year + "<BR>")
//-->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

sciguyryan
10-19-2003, 02:08 PM
its ok, solved - updated code: still want some comments though :thumbsup:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!--
var ampm = "a.m."
var mydate = new Date()
var monthday = mydate.getDate()
if (monthday == 4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||24||25||26||27||28||29||30)
{
var monthday = monthday + "<SUP>th</SUP>";
}
else if (monthday == 1||21||31)
{
var monthday = monthday + "<SUP>st</SUP>";
}
else if (monthday == 2||22)
{
var monthday = monthday + "<SUP>nd</SUP>";
}
else if (monthday == 3||23)
{
var monthday = monthday + "<SUP>rd</SUP>";
}
var month = mydate.getMonth()
if (month == 0)
{
var month = "January";
}
else if (month == 1)
{
var month = "Febuary";
}
else if (month == 2)
{
var month = "March";
}
else if (month == 3)
{
var month = "April";
}
else if (month == 4)
{
var month = "May";
}
else if (month == 5)
{
var month = "June";
}
else if (month == 6)
{
var month = "July";
}
else if (month == 7)
{
var month = "August";
}
else if (month == 8)
{
var month = "September";
}
else if (month == 9)
{
var month = "October";
}
else if (month == 10)
{
var month = "November";
}
else if (month == 11)
{
var month = "December";
}
var day = mydate.getDay()
if (day == 1)
{
var day = "Monday";
}
else if (day == 2)
{
var day = "Tuesday";
}
else if (day == 3)
{
var day = "Wednesday";
}
else if (day == 4)
{
var day = "Thursday";
}
else if (day == 5)
{
var day = "Friday";
}
else if (day == 6)
{
var day = "Saturday";
}
else if (day == 0)
{
var day = "Sunday";
}
var year = mydate.getYear()
var hours = mydate.getHours()
if (hours >= 12)
{
hours = hours - 12;
ampm = "p.m."
}
if (hours == 0)
{
hours = 12;
}
var minutes = mydate.getMinutes()
if (minutes <= 9)
{
minutes = "0" + minutes;
}
document.write("The Time is: " + hours + ":" + minutes +" " + ampm)
document.write("<BR>" + "The full date is: "+ day +", " + month + " the " + monthday + "&nbsp;" + year + "<BR>")
//-->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

Vladdy
10-19-2003, 02:16 PM
That is one LONG way of doing things....
Month name:


function Date.prototype.getMonthName()
{ var months=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
return months[this.getMonth()];
}

Date suffix:


function Date.prototype.getDateSuffix()
{ var suffix=['st','nd','rd','th'];
var dateMod = this.getDate%10;
return suffix[dateMod<4?dateMod-1:3];
}

sciguyryan
10-19-2003, 03:10 PM
Thank you I will cange it.

sciguyryan
10-19-2003, 03:15 PM
One probem - I cant get it to work? - Can you help?

sciguyryan
10-19-2003, 07:46 PM
Why was this moved? It was intended to be a posted script?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum