We can extract or get the minute parts from the date object by using getMinutes() function. The value will be from 0 to 59. Here is the simple code
var dt= new Date();
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
function timer(){
var dt= new Date();
document.getElementById(\"d1\").innerHTML = dt.getMinutes();
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 mailing list

* indicates required
Subscribe to plus2net
Your Rating


More on JavaScript Date & Time

Post Comment This is for short comments only. Use the forum for more discussions.

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2018 All rights reserved worldwide Privacy Policy Disclaimer