JavaScript: Compute Date Range

By Xah Lee. Date: . Last updated: .

The best way to compute date range is to convert time to epoch milli-seconds (returned by Date.now() or date.getTime()) then add or minus by milli-seconds, then convert it back to whichever time format you want.

// returns a date object that's n secs in the future
const nSecsInFuture = (x => (new Date(Date.now() + 1000 * x)));

// 1 min in future
console.log( nSecsInFuture(60) );

// sample output
// 2020-09-12T18:05:06.454Z

JavaScript Date

βˆ‘ JS in Depth
XAH Β BUY NOW

JS in Depth

JS Obj Ref

DOM


JS in Depth

Basic Syntax

Value Types

Variable

String

Function

Property

Object and Inheritance

Array

Constructor/Class

Iterable 🌟

Misc