/    Sign up×
Community /Pin to ProfileBookmark

Formatting lastModified

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>

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@pyroJun 25.2003 — Yes you can...just split it at the spaces, and only take the first part:

&lt;script type="text/javascript"&gt;
var lm=document.lastModified;
lm = lm.split(" ");
document.write("Last modified: "+ lm[0])
&lt;/script&gt;
Copy linkTweet thisAlerts:
@askohenauthorJun 25.2003 — Thanks for your help. -A
Copy linkTweet thisAlerts:
@pyroJun 25.2003 — You're welcome. ?
Copy linkTweet thisAlerts:
@CharlesJun 25.2003 — [font=monospace]<script type="text/javascript">

<!--

alert (new Date(document.lastModified).toDateString());

// -->

</script>[/font]
Copy linkTweet thisAlerts:
@askohenauthorJun 25.2003 — What about a way to transform 6/25/2003 to 06 June 2003?
Copy linkTweet thisAlerts:
@CharlesJun 25.2003 — [font=monospace]<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>[/font]
Copy linkTweet thisAlerts:
@pyroJun 25.2003 — &lt;script type="text/javascript"&gt;
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)
&lt;/script&gt;
Copy linkTweet thisAlerts:
@askohenauthorJun 25.2003 — Cool. When I get a chance I'll try and figure out how you did that. Thanks again.
×

Success!

Help @askohen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...