Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript date get future 5minutes

let interval = 15 * 60 * 1000;  // 15min in ms
let myDate = new Date(); // date that should be round to nearest 15min

// date with nearest 15min
let newDate = new Date(Math.round(myDate / interval) * interval); 
// note: for NEXT 15min interval, use Math.ceil()

// examples
// myDate('2022-08-11 09:05:13') -> newDate = '2022-08-11 09:00:00'
// myDate('2022-08-11 09:08:11') -> newDate = '2022-08-11 09:15:00'
// myDate('2022-08-11 09:51:16') -> newDate = '2022-08-11 09:45:00'
// myDate('2022-08-11 09:52:48') -> newDate = '2022-08-11 10:00:00'
Comment

javascript date get future 5minutes

let interval = 5 * 60 * 1000;  // 5min in ms
let myDate = new Date(); // date that should be round to next 5min

// date with next/future 5min
let newDate = new Date(Math.ceil(myDate / interval) * interval);
// note: for NEAREST 5min interval, use Math.round()

// examples
// myDate('2022-08-11 08:01:18') -> newDate = '2022-08-11 08:05:00'
// myDate('2022-08-11 08:04:59') -> newDate = '2022-08-11 08:05:00'
// myDate('2022-08-11 08:50:08') -> newDate = '2022-08-11 08:55:00'
// myDate('2022-08-11 08:57:14') -> newDate = '2022-08-11 09:00:00'
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript string change character at index 
Javascript :: javascript replace all occurrences of string 
Javascript :: javascript check if time is less than 
Javascript :: how to fetch the all input element id value 
Javascript :: node redis json set key 
Javascript :: jquery remove option from dropdown 
Javascript :: cache remove using ajax 
Javascript :: chart js stacked bar group 
Javascript :: javascript newline in alert 
Javascript :: mongoose check if string is objectid 
Javascript :: nodejs express hot reload 
Javascript :: merge two objects javascript 
Javascript :: javascript line through 
Javascript :: what is data node in big data 
Javascript :: collection to array javascript 
Javascript :: get dirname to last directory node 
Javascript :: javascript error discord 
Javascript :: how to update kali linux on virtualbox 
Javascript :: how to change text to italic in javascript 
Javascript :: react navigation navigator types 
Javascript :: refresh after delete in express 
Javascript :: promise recursive settimeout 
Javascript :: react img not showing 
Javascript :: axios get status code 
Javascript :: javascript flatten an array 
Javascript :: node cron every 10 minutes 
Javascript :: flip a coin javascript 
Javascript :: how to make a show password button 
Javascript :: website edit js 
Javascript :: react native scrollview map 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =