Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.07 KB

prefer-date-now.md

File metadata and controls

42 lines (29 loc) · 1.07 KB

Prefer Date.now() to get the number of milliseconds since the Unix Epoch

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

Date.now() is shorter and nicer than new Date().getTime(), and avoids unnecessary instantiation of Date objects.

Fail

const foo = new Date().getTime();
const foo = new Date().valueOf();
const foo = +new Date;
const foo = Number(new Date());
const foo = new Date() * 2;

Pass

const foo = Date.now();
const foo = Date.now() * 2;