Created
March 2, 2021 13:04
-
-
Save ilomon10/12aba71af32cf4c0992a912e1c883f55 to your computer and use it in GitHub Desktop.
Round moment.js object time to nearest interval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ref: https://stackoverflow.com/a/25323966/8271526 | |
function dateRounding(interval, unit, date) { | |
const start = moment(date); | |
const remainder = interval - (start.get(unit) % interval); | |
const dateTime = moment(start).add(remainder, unit).format("DD.MM.YYYY, h:mm:ss a"); | |
return dateTime; | |
} | |
dateRounding(30, "minute", "2018-12-08 09:42"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment