I'm looking for a way to change the value returned from javascript's new Date()
function.
In general - I'm looking for a way to write an extension that will give the user the ability to set his timezone (or diff from the time of his system's clock) without changing time/timezone on his computer.
I checked the chrome extension api but found nothing there. Will appreciate it if someone can point me at the right direction.
Method 1: Using Developer Tools to Change Chrome TimezoneOpen DevTools in Chrome -> Open the Console drawer. Click on the three-dotted menu -> Click on More tools -> Sensors. From the Sensors tab, set the location according to your preference and define the specific timezone.
Click the Edit Inspection button, and confirm you want to edit by clicking the OK button the alert message that appears. Use the calendar icon in the below the General Inspector comments text box on the right side of the screen to select a new return date. Then click the Save Changes button.
I have seen some solutions involving overriding javascript's getTime()
method:
Date.prototype.getTime = function() { return [DATE + OFFSET] };
usage:
(new Date).getTime();
(source)
Apparently the time does not come from the browser but rather the operating system. So my suggestion would be to inject this javascript using a content script, and in your overriding function, you can offset the date/time by however much you would like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With