JS: 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

BUY Ξ£JS JavaScript in Depth