<!DOCTYPE html>
<
html
>
<
head
>
<
title
>
Round off a Date Object to 5
minutes in JavaScript.
</
title
>
</
head
>
<
body
style
=
"text-align:center;"
>
<
h1
style
=
"color:green;"
>
GeeksforGeeks
</
h1
>
<
p
id
=
"gfg"
style="font-size: 20px;
font-weight: bold">
</
p
>
<
button
onclick
=
"GFG_Fun1();"
>
Round Down
</
button
>
<
button
onclick
=
"GFG_Fun2();"
>
Round Up
</
button
>
<
p
id
=
"geeks"
style="font-size: 26px;
font-weight: bold;color: green;">
</
p
>
<
script
>
var up = document.getElementById('gfg');
var down = document.getElementById('geeks');
var date = new Date();
up.innerHTML = "Click on the button to "
+ "round the date as specified."
+ "<
br
><
br
>Date - " + date;
function GFG_Fun1() {
// ms in 5 minutes.
var coff = 1000 * 60 * 5;
down.innerHTML = new Date(
Math.floor(date / coff) * coff);
}
function GFG_Fun2() {
// ms in 5 minutes.
var coff = 1000 * 60 * 5;
down.innerHTML = new Date(
Math.ceil(date / coff) * coff);
}
</
script
>
</
body
>
</
html
>