Website Design United States, Website Design California, Website Designing United States, Website Designing California

Document Last Modified - JavaScript

This JavaScript code will allow you to display the date a file was last modified. I set it up to allow you to change the way the date is displayed by using the date_format variable. The way the date will be shown is listed in the code depending on what you set date_format to (a value between 1-8).

I also allowed for you to change the "divider" of the dates for formats such as: 12/25/2004. If you'd like to have the date shown as 12.25.2004 then change the divider variable value to "." -- var divider = ".";

The source code above should be placed in between the HEAD tags of your HTML document.

To call the script in your page use:

document.write(modified_date());Unknown

If you do not wish for "Unknown" to be displayed you can remove it from between the NOSCRIPT tags.

<script type="text/javascript">
// Document Last Modified - JavaScript
// (c)2004 Dan Gronitz
//
// This code was for Programmer's Corner (http://www.programmers-corner.com/index.php)
// and can be used freely for personal (non-commercial) use as long as this notice
// remains with the code.
//
function modified_date(){
var date_format = 1;
var date_divider = "/";
// Date Formats:
// 1) 12/25/2004 (Month/Day/Year) - seperated with your date_divider set as "." - (12.25.2004)
// 2) 25/12/2004 (Day/Month/Year) - seperated with your date_divider set as "." - (25.12.2004)
// 3) December 25, 2004
// 4) 25 December 2004
// 5) Saturday - December 25, 2004
// 6) Saturday - 25 December 2004
// 7) Saturday 12/25/2004 (Weekday Month/Day/Year)
// 8) Saturday 25/12/2004 (Weekday Day/Month/Year)

var date = new Date(Date.parse(document.lastModified));

var year = date.getFullYear();
var decimal_month = date.getMonth();
var this_month = decimal_month + 1;
var decimal_day = date.getDate();
var this_day = date.getDay();

var month = new Array();
month[0] = "January ";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";

var day = new Array();
day[0] = "Sunday";
day[1] = "Monday";
day[2] = "Tuesday";
day[3] = "Wednesday";
day[4] = "Thursday";
day[5] = "Friday";
day[6] = "Saturday";

var date_mod;

switch(date_format){
case 1:
date_mod = this_month + date_divider + decimal_day + date_divider + year;
break;
case 2:
date_mod = decimal_day + date_divider + this_month + date_divider + year;
break;
case 3:
date_mod = month[decimal_month] + " " + decimal_day + ", " + year;
break
case 4:
date_mod = decimal_day + " " + month[decimal_month] + " " + year;
break;
case 5:
date_mod = day[this_day] + " - " + month[decimal_month] + " " + decimal_day + ", " + year;
break;
case 6:
date_mod = day[this_day] + " - " + decimal_day + " " + month[decimal_month] + " " + year;
break;
case 7:
date_mod = day[this_day] + " " + this_month + date_divider + decimal_day + date_divider + year;
break;
case 8:
date_mod = day[this_day] + " " + decimal_day + date_divider + this_month + date_divider + year;
break;
default:
date_mod = this_month + date_divider + decimal_day + date_divider + year;
break;
}

return date_mod;
}
</script>

WEB DESIGN INDIA
42 B Malviya Nagar , New Delhi-110017

Skype: manmeetsi
Email: support.webdesignindia@gmail.com
Tel: 91-011-40502005, 9810067295

 















 


© 2008-2009 dotnet4all.com