Click to See Complete Forum and Search --> : Formatting lastModified
askohen
06-25-2003, 01:26 PM
What's the best way to insert a date reflecting the date a page was last modified?
I was thinking of using the javascript lastModified property. I know that results will depend on the browser, but can I somehow customize the output so that just the month and date show?
Here's my code:
<SCRIPT language="JavaScript">
var lm=document.lastModified;
document.write("Last modified: "+ lm)
</SCRIPT>
Yes you can...just split it at the spaces, and only take the first part:
<script type="text/javascript">
var lm=document.lastModified;
lm = lm.split(" ");
document.write("Last modified: "+ lm[0])
</script>
askohen
06-25-2003, 01:52 PM
Thanks for your help. -A
Charles
06-25-2003, 02:12 PM
<script type="text/javascript">
<!--
alert (new Date(document.lastModified).toDateString());
// -->
</script>
askohen
06-25-2003, 02:21 PM
What about a way to transform 6/25/2003 to 06 June 2003?
Charles
06-25-2003, 02:32 PM
<script type="text/javascript">
<!--
Date.prototype.toDateString = function () {return [this.getDate < 10 ? '0' + this.getDate() : this.getDate(), ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][this.getMonth()], this.getFullYear()].join(' ')}
alert (new Date(document.lastModified).toDateString())
// -->
</script>
<script type="text/javascript">
date = new Date(document.lastModified);
day = date.getDate();
month = date.getMonth();
year = date.getYear();
months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
month = months[month];
document.write("Last modified: "+ day +" "+ month +" "+year)
</script>
askohen
06-25-2003, 02:40 PM
Cool. When I get a chance I'll try and figure out how you did that. Thanks again.