charles_belov — 2010-06-04T16:49:07-04:00 — #1
The value of lastModifier varies from browser to browser. For example, for a server writing the header:
Last-modified: Fri, 04 Jun 2010 20:41:59 GMT
Safari 4 puts out a literal string that is exactly what is found in the document header,
Fri, 04 Jun 2010 20:41:59 GMT
Firefox 3.6 and Internet Explorer 8 put out a reformatted string in local time (not sure if it's the server's local or the browsers local, since my server is in the same time zone).
Is there any way to get a consistent lastModified string without doing browser sniffing? I would expect sniffing to not be resilient to change, given that lastModified output has changed before in browser history, based on posts from several years ago, and will likely change again. I prefer Safari's method, as I would only have to know if my server's format changed.
charles_belov — 2010-06-04T19:09:33-04:00 — #2
Thanks! That got me there. Here's the code I ultimately wound up with:
var headerTime = new Date(Date.parse(document.lastModified));
headerTime = headerTime.valueOf();
mrhoo — 2010-06-04T17:10:15-04:00 — #3
if s is the string returned from the lastModifies header, then
new Date(Date.parse(s)).toUTCString() will return a slightly different string between browsers,
but they will all be an expression of GMT time, not server or local time.
You can format the string as you please from the Date object in
new Date(Date.parse(s)), but the UTCString method is close enough for most purposes.