Post by [dmsuperman] on Jan 4, 2006 14:13:32 GMT
Description: This is a neat little function to get the date in whichever format you desire.
Creator: [dmsuperman]
Board: Open Source
<script type="text/javascript">
<!--
//- Date function by [dmsuperman]
//- You may remove this header, use as you wish, but don't claim creation
//- Example format:
//- %M %d%l, %Y at %h:%t %A, %s %w
//- March 3rd, 2005 at 8:08 AM, 1 second
/*
Code...Description...........Example
%Y......Year 4 digit...........2005
%y......Year 2 digit...........05
%M......Month word.........March
%m......Month number.....3
%u.......Month number.....03
%d.......Date....................21
%h.......Hour....................8
%t........Minute.................09
%s.......Second.................21
%A.......AM or PM..............AM
%a.......am or pm.............am
%w......seconds label.......second/seconds
%l........Date label.............rd (for 3rd)
*/
function getTime(format){
var months = new Array();
months[1] = "January";
months[2] = "February";
months[3] = "March";
months[4] = "April";
months[5] = "May";
months[6] = "June";
months[7] = "July";
months[8] = "August";
months[9] = "September";
months[10] = "October";
months[11] = "November";
months[12] = "December";
var date = new Date();
var year = date.getYear();
var month = date.getMonth();
var day = date.getDate();
var hour = date.getHours();
var seconds =date.getSeconds();
if(hour >= 12){
amorpm = "pm";
amorpm2 = "PM";
hour -= 12;
}else{
amorpm = "am";
amorpm2 = "AM";
}
var minute = date.getMinutes();
if(minute<10){
minute = "0" + minute;
}
if(seconds==1){
var secondsWord = "second";
}else{
var secondsWord = "seconds";
}
var monthWord = months[month];
var shortYear = year-2000;
if(shortYear<10){
shortYear = "0" + shortYear;
}
if(month<10){
month2 = "0" + month;
}else{
month2 = month;
}
if(day==1){
dLabel = "st";
}else if(day==2){
dLabel = "nd";
}else if(day==3){
dLabel = "rd";
}else{
dLabel = "th";
}
var newDate = format.replace("%Y", year).replace("%d", day).replace("%m", month).replace("%h", hour).replace("%M", monthWord).replace("%a", amorpm).replace("%s", seconds).replace("%w", secondsWord).replace("%t", minute).replace("%y", shortYear).replace("%A", amorpm2).replace("%u", month2).replace("%l", dLabel);
return(newDate);
}
document.write(getTime("%M %d%l, %Y at %h:%t %A, %s %w"));
//-->
</script>
Creator: [dmsuperman]
Board: Open Source
<script type="text/javascript">
<!--
//- Date function by [dmsuperman]
//- You may remove this header, use as you wish, but don't claim creation
//- Example format:
//- %M %d%l, %Y at %h:%t %A, %s %w
//- March 3rd, 2005 at 8:08 AM, 1 second
/*
Code...Description...........Example
%Y......Year 4 digit...........2005
%y......Year 2 digit...........05
%M......Month word.........March
%m......Month number.....3
%u.......Month number.....03
%d.......Date....................21
%h.......Hour....................8
%t........Minute.................09
%s.......Second.................21
%A.......AM or PM..............AM
%a.......am or pm.............am
%w......seconds label.......second/seconds
%l........Date label.............rd (for 3rd)
*/
function getTime(format){
var months = new Array();
months[1] = "January";
months[2] = "February";
months[3] = "March";
months[4] = "April";
months[5] = "May";
months[6] = "June";
months[7] = "July";
months[8] = "August";
months[9] = "September";
months[10] = "October";
months[11] = "November";
months[12] = "December";
var date = new Date();
var year = date.getYear();
var month = date.getMonth();
var day = date.getDate();
var hour = date.getHours();
var seconds =date.getSeconds();
if(hour >= 12){
amorpm = "pm";
amorpm2 = "PM";
hour -= 12;
}else{
amorpm = "am";
amorpm2 = "AM";
}
var minute = date.getMinutes();
if(minute<10){
minute = "0" + minute;
}
if(seconds==1){
var secondsWord = "second";
}else{
var secondsWord = "seconds";
}
var monthWord = months[month];
var shortYear = year-2000;
if(shortYear<10){
shortYear = "0" + shortYear;
}
if(month<10){
month2 = "0" + month;
}else{
month2 = month;
}
if(day==1){
dLabel = "st";
}else if(day==2){
dLabel = "nd";
}else if(day==3){
dLabel = "rd";
}else{
dLabel = "th";
}
var newDate = format.replace("%Y", year).replace("%d", day).replace("%m", month).replace("%h", hour).replace("%M", monthWord).replace("%a", amorpm).replace("%s", seconds).replace("%w", secondsWord).replace("%t", minute).replace("%y", shortYear).replace("%A", amorpm2).replace("%u", month2).replace("%l", dLabel);
return(newDate);
}
document.write(getTime("%M %d%l, %Y at %h:%t %A, %s %w"));
//-->
</script>