Skip to content

Latest commit

Β 

History

History
39 lines (26 loc) Β· 1.11 KB

File metadata and controls

39 lines (26 loc) Β· 1.11 KB

prefer-date-now

πŸ“ Prefer Date.now() to get the number of milliseconds since the Unix Epoch.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ”§ 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.

Examples

// ❌
const foo = new Date().getTime();

// ❌
const foo = new Date().valueOf();

// ❌
const foo = +new Date;

// ❌
const foo = Number(new Date());

// βœ…
const foo = Date.now();
// ❌
const foo = new Date() * 2;

// βœ…
const foo = Date.now() * 2;