Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Round date to future 5min

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 :: nevigate on button click in angular 
Javascript :: Detecting by how much user has scrolled | get how much i scroll in js 
Javascript :: disable long press on chrome 
Javascript :: wait until a function finishes javascript 
Javascript :: make object readonly javascript 
Javascript :: javascript primitive data types 
Javascript :: fizzbuzz javascript 
Javascript :: try...catch...throw javascript 
Javascript :: .fetch method 
Javascript :: dropzone remove error file 
Javascript :: nodejs exit code 
Javascript :: test window.location.reload() jest 
Javascript :: windows scroll condition 
Javascript :: react native showing double header stack and drawer menu 
Javascript :: javascript ip address 
Javascript :: javascript closure 
Javascript :: array as json 
Javascript :: how to export multiple functions react from one file 
Javascript :: moment 
Javascript :: Substring in Javascript using substring 
Javascript :: jquery close 
Javascript :: express json body 
Javascript :: load data from json server into html using jquery 
Javascript :: javascript sort array of objects by value of key in object 
Javascript :: remove falsy values from array with lodash 
Javascript :: preventdefault javascript 
Javascript :: indexof javascript duplicate arrays 
Javascript :: js map key value 
Javascript :: get url of page in background script 
Javascript :: fizz buzz program in javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =