avoid-Date-timing.rst (752B)
1 avoid-Date-timing 2 ================= 3 4 Rejects grabbing the current time via Date.now() or new Date() for timing 5 purposes when the less problematic performance.now() can be used instead. 6 7 The performance.now() function returns milliseconds since page load. To 8 convert that to milliseconds since the epoch, use: 9 10 .. code-block:: js 11 12 performance.timing.navigationStart + performance.now() 13 14 Often timing relative to the page load is adequate and that conversion may not 15 be necessary. 16 17 Examples of incorrect code for this rule: 18 ----------------------------------------- 19 20 .. code-block:: js 21 22 Date.now() 23 24 Examples of correct code for this rule: 25 --------------------------------------- 26 27 .. code-block:: js 28 29 new Date('2017-07-11'); 30 performance.now()