4

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 the page in Chrome and in Firefox. Firefox displays the time correctly - in my local time. Chrome displays it in UTC.

  1. How do I get Chrome to display the datetime in either (a) local time of whoever is vieweing the page or (b) in PDT/PST (simpler)

  2. Is there a solution that will display local time on both Chrome and Firefox (and others)?

Thanks.

Myx
  • 1,792
  • 5
  • 23
  • 37

1 Answers1

1

I've checked how it is accomplished on Google Chrome but frankly I haven't been able to find anything useful except these two methods 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 the 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 from this address: Convert UTC Epoch to local date with javascript

Community
  • 1
  • 1
Tarik
  • 79,711
  • 83
  • 236
  • 349