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 and logicalStrict presets.

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
const timestamp: number
timestamp
= new
var Date: DateConstructor
new () => Date (+3 overloads)
Date
().
Date.getTime(): number

Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC.

getTime
();
const
const timestamp: number
timestamp
= new
var Date: DateConstructor
new () => Date (+3 overloads)
Date
().
Date.valueOf(): number

Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC.

valueOf
();
const
const timestamp: number
timestamp
= +new
var Date: DateConstructor
new () => Date (+3 overloads)
Date
();
const
const timestamp: number
timestamp
=
var Number: NumberConstructor
(value?: any) => number

An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.

Number
(new
var Date: DateConstructor
new () => Date (+3 overloads)
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 ❤️‍🔥 around the world by the Flint team and contributors.