Hi,
I need to calculate the time since this .htm file was last modified. {which I can then use in a calculation, rather than display, so days&decimals format would be OK}
I can get the time NOW, but I am having trouble understanding the format/content of the document.lastModified field.
Any help would be much appreciated - thanks
I have a function to calculate the difference between the 2 dates, but when i run it I get: Object doesn't support this property or method
Expand|Select|Wrap|Line Numbers
- <script language="JavaScript" type="text/javascript">
- <!--
- function days_between(date1, date2) { //calculates day & fractions of days between 2 dates_times
- var ONE_DAY = 1000 * 60 * 60 * 24 // Nb The number of milliseconds in one day
- // Convert both dates to milliseconds
- var date1_ms = date1.getTime()
- var date2_ms = date2.getTime()
- // Calculate the difference in milliseconds
- var difference_ms = Math.abs(date1_ms - date2_ms)
- // Convert back to days&decimals and return
- // return Math.round(difference_ms/ONE_DAY) // forget about rounding
- return (difference_ms/ONE_DAY)
- }
- //-->
- </script>
Expand|Select|Wrap|Line Numbers
- <script type="text/javascript">
- <!--
- var current_date = new Date()
- document.writeln("Current time: " + current_date + "<p />") // print for testing
- lastmod = document.lastModified // get string of last modified date
- lastmoddate = Date.parse(lastmod) // convert modified string to date
- if(lastmoddate == 0){ // unknown date (or January 1, 1970 GMT)
- document.writeln("Last Modified: Unknown")
- } else {
- document.writeln("Last Modified: " + lastmod + "<p />")
- // Call the days_between function
- var time_elapsed = days_between(current_date, lastmod )
- // and for testing just print it for now..
- document.writeln("Time elapsed =: " + time_elapsed + "<p />")
- }
- //-->
- </script>