Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript date get nearest 15 minutes

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

PREVIOUS NEXT
Code Example
Javascript :: nuxt lang 
Javascript :: how you can use javascript to play the sound for the button color selected 
Javascript :: rounding off numbers javascript 
Javascript :: javascript get url parameters 
Javascript :: regex contains string in end 
Javascript :: multidimensional array push in jquery 
Javascript :: check if input is a number javascript 
Javascript :: create react app failed with code 1 
Javascript :: css div at bottom of div 
Javascript :: ngchange angular 8 
Javascript :: copy file javascript 
Javascript :: how to change text of div in javascript 
Javascript :: javascript dice throw 
Javascript :: electron get exe path 
Javascript :: flutter http request 
Javascript :: javascript onclick image 
Javascript :: how to send header in axios 
Javascript :: how to stop server of react js 
Javascript :: array value check javascript 
Javascript :: installing prop-types 
Javascript :: merge array no duiplicates js 
Javascript :: delay statement in js 
Javascript :: get page link angular 
Javascript :: google sheet app script 
Javascript :: how to convert milliseconds to time in javascript 
Javascript :: on click jqueyr 
Javascript :: jquery check if has class 
Javascript :: body click function removeclass 
Javascript :: internal/modules/cjs/loader.js:1122 
Javascript :: remove jquery 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =