dateNowTimestamps
Prefer the shorter
Date.now()to get the number of milliseconds since the Unix Epoch.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
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())
Examples
Section titled “Examples”const const timestamp: number
timestamp = new var Date: DateConstructornew () => Date (+4 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: DateConstructornew () => Date (+4 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: DateConstructornew () => Date (+4 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: DateConstructornew () => Date (+4 overloads)
Date());const const timestamp: number
timestamp = var Date: DateConstructor
Enables basic storage and retrieval of dates and times.
Date.DateConstructor.now(): number
Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).
now();const const date: Date
date = new var Date: DateConstructornew () => Date (+4 overloads)
Date();const const formattedDate: string
formattedDate = const date: Date
date.Date.toISOString(): string
Returns a date as a string value in ISO format.
toISOString();Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
useDateNow - ESLint:
unicorn/prefer-date-now - Oxlint:
unicorn/prefer-date-now