开发者

Change browser time to test return value of Date()?

Is there any way t开发者_如何学Goo change the browser's time without manipulating the system clock?


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.


You can run the browser in a virtual machine (VMWare/VirtualPC/etc.) and change the time of the OS in the VM.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜