Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript date get nearest 5 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 domcontentloaded 
Javascript :: javascript sort array strings alphabetically 
Javascript :: express serve home page 
Javascript :: nodejs json beautify 
Javascript :: angular formData print values 
Javascript :: how to change tab color react bootstraps customixation 
Javascript :: how to make a rectangle in javascript 
Javascript :: Read text file in vanilla JS 
Javascript :: get element by id in javascript 
Javascript :: vue computed composition api 
Javascript :: remove empty element from array js 
Javascript :: nodejs wait function 
Javascript :: clear whitespace from object javascript 
Javascript :: vue shorthand 
Javascript :: zoom out browser javascript 
Javascript :: json.stringify parameters 
Javascript :: check the string is vowel or not javascript 
Javascript :: knex.js count 
Javascript :: add sass autoprefixer to react 
Javascript :: props type 
Javascript :: refresh after delete in node 
Javascript :: combinereducers 
Javascript :: insert image in react 
Javascript :: axios get error response message 
Javascript :: javascript clear all cookies 
Javascript :: react native text input right 
Javascript :: var_dump in javascript 
Javascript :: how to get innerhtml value in javascript 
Javascript :: how to edit website 
Javascript :: javascripte list length 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =