DenverCoder9 DenverCoder9 - 10 months ago 59
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();