Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How do I remove seconds from the time in a getLastMod script?

    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.
    Last edited by klk3644; 05-20-2009 at 10:05 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    lastModif.toLocaleString().replace(/:\d{2}\s/,' ')

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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>

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    By 'didn't work' you mean

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry for my lack of clarification. The end result did not change, it is still displaying the time with the hours, minutes and seconds.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Skipped the iframe for simplicity -

    Code:
    <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>

  • Users who have thanked adios for this post:

    klk3644 (05-20-2009)

  • #7
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you, thank you. That worked.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •