getMinutes()

We can extract or get the minute parts from the date object by using getMinutes() function.
<script>
var DateObj = new Date('September 21, 2018 05:35:32');
var minutes = DateObj.getMinutes();
document.write(minutes); // output is 35 
</script>
The value will be from 0 to 59. Here is the simple code to get current minutes value.
var dt= new Date();
document.write(dt.getMinutes());
Here is the output based on your time zone and date and time of your computer
We will get minutes from this date object. We can further work on this minutes part and set it to previous or advance value by using setMinutes function.

Displaying changing minutes value

Above display of minute shows the value at the time of page loading. To display real time or changing minutes we have to run this code again after an interval. For this we will use the setTimeout function.

Here is the code to keep inside HEAD tag of the page
<script>
function timer(){
var dt= new Date();
document.getElementById(\"d1\").innerHTML = dt.getMinutes();
setTimeout('timer()',1000);
}
</script>
The HTML part to show the SPAN tag with id, you can change the background color as per your requirement.
<span id='d1' style="background-color: #FFFF00"></span>
To initiate the timer function we have to add onload to our body tag.
<body onload=timer();>
The output of this code is here, keep watching for a minute and see how the time ( minutes part only) changes.



Using this concept we can display a real time changing CLOCK here.
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com




    Post your comments , suggestion , error , requirements etc here .




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer