...

View Full Version : Resolved How do I remove seconds from the time in a getLastMod script?



klk3644
05-20-2009, 08:33 PM
Below is a copy of the javascript I am using to get the last modified date of a file named "lastupdated.txt". The script is currently showing me Day, Month, Date, Year, Hour, Minutes, Seconds and AM/PM (Example: Wednesday, May 20, 2009 1:38:23 PM) and works perfectly. I would like to tweak the output a little and I like everything about it except I would like to eliminate the seconds in the time. Does anyone have a suggestion?

<script type="text/javascript">
function getLastMod(){
var myFrm = document.getElementById('myIframe');
var lastModif = new Date(myFrm.contentWindow.document.lastModified);
document.getElementById('LastModified').innerHTML = "Updated: " + lastModif.toLocaleString();
}
</script>

I appreciate the help.

adios
05-20-2009, 09:17 PM
lastModif.toLocaleString().replace(/:\d{2}\s/,' ')

klk3644
05-20-2009, 09:35 PM
Well, it didn't work. Below is what I have, hope I did it correct. Thanks for your help.

<script type="text/javascript">
function getLastMod(){
var myFrm = document.getElementById('myIframe');
var lastModif = new Date(myFrm.contentWindow.document.lastModified);
document.getElementById('LastModified').innerHTML = "Updated: " + lastModif.toLocaleString().replace(/:\d{2}\s/,' ');
}
</script>

adios
05-20-2009, 09:43 PM
By 'didn't work' you mean :confused:

klk3644
05-20-2009, 09:48 PM
Sorry for my lack of clarification. The end result did not change, it is still displaying the time with the hours, minutes and seconds.

adios
05-20-2009, 09:51 PM
Skipped the iframe for simplicity -


<html>
<head>
<script type="text/javascript">

function getLastMod(){
//var myFrm = document.getElementById('myIframe');
var lastModif = new Date(document.lastModified);
document.getElementById('LastModified').innerHTML = "Updated: " + lastModif.toLocaleString().replace(/:\d{2}\s/,' ')
}
onload=getLastMod
</script>
</head>
<body>
<div id="LastModified"></div>
</body>
</html>

klk3644
05-20-2009, 10:01 PM
:)Thank you, thank you. That worked.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum