Click to See Complete Forum and Search --> : Last Modified


cyberchimp
07-21-2003, 09:58 AM
I've been using

document.write(document.lastModified)

at the foot of one of my pages in order to show when the page was last updated. The results vary from one browser to the next (surprise, surprise):

IE: 06/26/2003 10:00:26
Opera: Thu, 26 Jun 2003 09:00:26 GMT
NN: Thursday, June 26, 2003 10:00:26

I have two questions:
(1) Is there any way of ensuring a greater degree of consistency across browsers (ie so that ALL browsers display the same combination of day, date, time and timezone)?
(2) Is there any way of removing the time stamp altogether (which I don't really need)?

Many thanks.

pyro
07-21-2003, 10:38 AM
Let's start with what you mean by 2. If you don't need the timestamp, just remove document.write(document.lastModified) ... What did you mean by that?

Khalid Ali
07-21-2003, 11:04 AM
here ya go....
the script below will do what you want it to do.


<script type="text/javascript">
<!--
var format = document.lastModified;
Date.prototype.lastModified=function(){
var date = new Date(format);
return date.getDate()+"/"+date.getMonth()+"/"+date.getFullYear();
}

function Process(){
var frm = document.getElementById("form1");
var len = frm.length;
}
//-->
</script>
</head>
<body class="body">
<script type="text/javascript">
document.write((new Date()).lastModified());
</script>

requestcode
07-21-2003, 11:08 AM
I think he means the hours - minutes and secs. Here is an example of one way you can do it:
<html>
<head>
<title>Write Todays Date</title>
</head>
<body>
<script language="JavaScript">
var mydate = new Date(document.lastModified);
var mymonth=mydate.getMonth()+1
// values for month,day,hours,minutes and seconds are check to see if they are less
// than 10. If they are a zero is add to the front of them. With out this a single
// digit would be displayed.
if(mymonth<10) {mymonth="0"+mymonth}
var myday=mydate.getDate()
if(myday<10) {myday="0"+myday}
var myyear=mydate.getFullYear()
document.write("document last modified "+mymonth+"/"+myday+"/"+myyear)
</script>
</body>
</html>

Charles
07-21-2003, 11:38 AM
You have several options once you have turned the date stamp into a Date object:

1) You can write your own method, as Khalid has suggested;

2) you can use new Date(document.lastModified).toLocaleString();

3) you can use new Date(document.lastModified).toDateString();

4) you can use new Date(document.lastModified).toTimeString().

Those last three will format the date according to the user's preference which is a very good thing.

cyberchimp
07-22-2003, 09:27 AM
Thanks for that guys - just what I wanted (and sorry if my reference to the time 'stamp' was unclear).