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 :: javascript date get future 5minutes 
Javascript :: how to install mongodb in node js 
Javascript :: js replace all 
Javascript :: get data from url javascript 
Javascript :: How to create react app with yarn, npx or npm 
Javascript :: Type io.invertase.firebase.BuildConfig is defined multiple times 
Javascript :: set variable to object without editing old object js 
Javascript :: convert hex code to rgb javascript 
Javascript :: indexof vs findindex 
Javascript :: fibonacci javascript 
Javascript :: .env file node js 
Javascript :: array.filter async 
Javascript :: js inline if 
Javascript :: async queue.push 
Javascript :: javascript add class 
Javascript :: request body empty express 
Javascript :: Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". 
Javascript :: click button javascript 
Javascript :: how to make option selected edit in jquery 
Javascript :: prop-types instalation 
Javascript :: How to calc() height in react native for styling 
Javascript :: react native scrollable 
Javascript :: javascript form submit on button click check if required fields not empty 
Javascript :: Navbar Componet Nextjs 
Javascript :: how to upload file in material ui 
Javascript :: linear gradient reactjs 
Javascript :: react 404 page not found 
Javascript :: sort by json fied in laravel 
Javascript :: internal/modules/cjs/loader.js:1122 return process.dlopen(module, path.toNamespacedPath(filename)); 
Javascript :: swap key value object javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =