Skip to content

dateNowTimestamps

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

✅ This rule is included in the ts logical preset.

Date.now() is shorter and more efficient than alternatives like new Date().getTime() because it avoids unnecessary instantiation of Date objects.

This rule reports patterns that create a Date object only to immediately extract the timestamp, such as:

  • new Date().getTime()
  • new Date().valueOf()
  • +new Date()
  • Number(new Date())
const timestamp = new Date().getTime();
const timestamp = new Date().valueOf();
const timestamp = +new Date();
const timestamp = Number(new Date());

This rule is not configurable.

If your codebase intentionally uses new Date().getTime() or similar patterns for stylistic consistency, you may disable this rule. Some older codebases may prefer the more explicit instantiation pattern.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.