DenverCoder9 DenverCoder9 - 1 year ago 95
Javascript Question

Change JavaScript Date in Chrome

Without having to change the date/time of the computer I am debugging, is there a way, either via the dev tools or by running some custom JavaScript in the console, to set / change what time or date Google Chrome thinks it is?

IE so that

new Date()
returns what you've set the browser to think it is, rather than the system's date.

There are ways around it, but it would be handy to debug different dates / times.

Answer Source


    var fake_date = new Date("October 6, 2016 11:13:00");

    //overriding date function
    Date = function(){return fake_date;};
    var new_date = new Date();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download