This is a discussion on How can I show the documents last modified date in the format: month, date, year, tim within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all... can anyone tell me How can I show the documents last modified date in the format: month, date, ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi all... can anyone tell me How can I show the documents last modified date in the format: month, date, year, time(GMT)? Thanks... |
| Sponsored Links |
| |||
| Hi all... <SCRIPT LANGUAGE = 'JavaScript'> function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this[i + 1] = makeArray.arguments[i]; } function getCorrectedYear(year) { year = year - 0; if (year < 70) return (2000 + year); if (year < 1900) return (1900 + year); return year; } Thanks... function y2k(number) { return (number < 1000) ? number + 1900 : number; } var months = new makeArray('January','February','March','April','Ma y','June','July','August','September','October','N ovember','December'); var date = new Date(document.lastModified); var dateY2K = new Date(getCorrectedYear(date.getYear()),date.getMont h(),date.getDate()); var dateGMT = dateY2K.toGMTString(); document.write(months[dateY2K.getMonth() + 1] + ', ' + dateY2K.getDate() + ', ' + y2k(dateY2K.getYear()) + ', ' + dateGMT.substring(dateGMT.indexOf(':')-2,dateGMT.indexOf(':')+6)); </SCRIPT> |
| |||
| da = new Date(document.lastModified) // Create a Date Object set to the last modifed date dy = da.getFullYear() // Get full year (as opposed to last two digits only) dm = da.getMonth() + 1 // Get month and correct it (getMonth() returns 0 to 11) dd = da.getDate() // Get date within month if ( dy < 1970 ) dy = dy + 100; // We still have to fix the millennium bug ys = new String(dy) // Convert year, month and date to strings ms = new String(dm) ds = new String(dd) if ( ms.length == 1 ) ms = "0" + ms; // Add leading zeros to month and date if required if ( ds.length == 1 ) ds = "0" + ds; ys = ys + "-" + ms + "-" + ds // Combine year, month and date in ISO format document.write ( "Last Updated " + ys ) // Display the result
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
| |||
| da = new Date(document.lastModified) // Create a Date Object set to the last modifed date db = da.toGMTString() // Convert to a String in "predictable formt" dc = db.split(" ") // Split the string on spaces if ( eval( dc[3] ) < 1970 ) dc[3] = eval( dc[3] ) +100 // Correct any date purporting to be before 1970 db = dc[1] + " " + dc[2] + " " + dc[3] // Ignore day of week and combine date, month and year document.write ( "Last Updated " + db ) |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Date format yymmdd | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 03-03-2008 09:07 PM |
| write to the document both the Last Modified and a review date, i.e. Last Modified | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 02-18-2008 08:34 PM |
| display the date in the format weekday, dd, month, year, for example Friday, 11 Dec98 | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 02-18-2008 08:31 PM |
| How do I format the Last-Modified date with javascript? | Pvinothkumar | HTML, CSS and Javascript Coding Techniques | 1 | 10-12-2007 11:17 PM |
| How to convert a date to a globally accepted date format, in DOT NET 2005? | Archer | C# Programming | 1 | 07-25-2007 03:21 AM |