prefer-date-now

March 27, 2026 ยท View on GitHub

๐Ÿ“ 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;