ROUNDING - JS

Java on dates

JDate: Date/time

Don't forget to check the documentation for the JDate Class

JS : Rounding off a time to 5 minutes (round, to the nearest value)

Rounding using the modulo is the standard method.

//Transform the date in millisecond timestamp
const timestamp = Date.parse("2021-01-01 15:13:00");

//Coeff for rounded 5min
const coeff = 5*60*1000;

let timestamp_rouded_5min = new Date(Math.round(timestamp / coeff) * coeff)

Was this article helpful?

Powered by Zendesk