Is there any way to change the browser's time without manipulating the system clock?
JavaScript Date getTime() getTime() returns the number of milliseconds since January 1, 1970 00:00:00.
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.
Mock the whole Date class with a fixed date instance Date = class extends Date { constructor(date) { if (date) { return super(date); } return currentDate; } }; expect(getCurrentDate()). toEqual(new Date('2019-05-14T11:01:58.135Z')); // Cleanup global. Date = realDate; });
The browser doesn't really "have time", it gets its time from the system clock. Of course, if you want to do something particularly nasty, you could override the Date functions.
Date.prototype.getTime = function() { return 1 };
(new Date).getTime(); // 1
So if you wanted to set the time to 1am November 4th 1989, you'd first find the time value:
(new Date('1989-11-04T01:00:00')).getTime() // Returns 626144400000
Then mock it in browser:
Date.prototype.getTime = function() { return 626144400000 };
No. The browser doesn't have a time. The system does.
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