Document.last Modified in Chrome

I have a webpage that displays the last time it was updated using document.write(document.lastModified) . I get two different results when I view a page in Chrome and Firefox. Firefox displays the time correctly - in my local time. Chrome displays it in UTC.

  • How to get Chrome to display the date and time in any (a) local time of the person who is viewing the page or (b) in PDT / PST (easier)

  • Is there a solution that will display local time for both Chrome and Firefox (and others)?

Thanks.

+4
source share
1 answer

I checked how this is done in Google Chrome, but to be honest, I could not find anything useful other than these two methods that you can use.

I believe this method can help you:

 function ToLocalDate (inDate) { var date = new Date(); date.setTime(inDate.valueOf() - 60000 * inDate.getTimezoneOffset()); return date; } 

Just check your browser type and call this method accordingly after.

Or you can also use the following method:

 var utc_string = '2011-09-05 20:05:15'; var local_string = (function(dtstr) { var t0 = new Date(dtstr); var t1 = Date.parse(t0.toUTCString().replace('GMT', '')); var t2 = (2 * t0) - t1; return new Date(t2).toString(); })(utc_string); 

These answers are taken at this address: Convert UTC era to local date using javascript

+1
source

All Articles