performance.now()与Date.now() [英] performance.now() vs Date.now()

查看:69
本文介绍了performance.now()与Date.now()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

performance.now()Date.now()有什么区别?

由于performace.now()更加一致和独立,我是否应该考虑将performance.now()替换为Date.now()?

Should I consider performance.now() as a replacement for Date.now() since performace.now() is more consistent and independent?

推荐答案

它们都有不同的用途.

performance.now() 相对于页面加载,并且在数量级上更为精确.用例包括基准测试和其他需要高分辨率时间的情况,例如媒体(游戏,音频,视频等)

performance.now() is relative to page load and more precise in orders of magnitude. Use cases include benchmarking and other cases where a high-resolution time is required such as media (gaming, audio, video, etc.)

应注意,performance.now()仅在较新的浏览器(包括IE10 +)中可用.

It should be noted that performance.now() is only available in newer browsers (including IE10+).

Date.now() 相对于Unix时代(1970-01-01T00:00:00Z),并取决于系统时钟.自JavaScript诞生以来,用例就包括相同的旧日期操作.

Date.now() is relative to the Unix epoch (1970-01-01T00:00:00Z) and dependent on system clock. Use cases include same old date manipulation ever since the beginning of JavaScript.

请参见毫秒级的时间足够:performance.now now方法(Internet Explorer )-MSDN 了解更多信息.

See When milliseconds are not enough: performance.now and now method (Internet Explorer) - MSDN for more information.

有关W3C的正式规范,请参见:高分辨率时间API

The official W3C spec can be found here: High Resolution Time API

这篇关于performance.now()与Date.now()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆