performance.now() 与 Date.now()

编程入门 行业动态 更新时间:2024-10-27 15:28:33
本文介绍了performance.now() 与 Date.now()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

我是否应该考虑将 performance.now() 作为 Date.now() 的替代品,因为 performace.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()

本文发布于:2023-10-24 02:54:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522731.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:performance   Date

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!