Format the utc time in 15 minutes.

for example, if the
time is 15:55, then 16:00 is displayed.
the time is 16:08, so it shows 16:15.
the time is 16:19, so it shows 16:30.

/ / = split line =
the following is the way I use, which can meet the demand, but I feel that it is very tedious to write, so humbly ask for more convenient way to write ~

.
function formatBeginTime(beginTime){
    let time = new Date(beginTime);
    let minute = time.getMinutes();
    if (minute > 0 && minute <= 15) {
        time.setMinutes(15);
    }
    if (minute > 15 && minute <= 30) {
        time.setMinutes(30);
    }
    if (minute > 30 && minute <= 45) {
        time.setMinutes(45);
    }
    if (minute > 45) {
        time.setMinutes(0);
        time.setHours(time.getHours()+1);
    }
    return time.getTime();
}
Sep.07,2021

  

take out the minutes, 15 and 15 + 15 to see who is closest

Menu