Javascript add hours to time -


i have javascript code should show time. works. wan't able add time though. lets want add 1 hour.

        <script type="text/javascript">         date.prototype.addhours = function(h) {                this.settime(this.gettime() + (h*60*60*1000));             return this;            }         // function gets current time , injects dom          function updateclock() {             // gets current time             var = new date();              // hours, minutes , seconds current time             var hours = now.gethours();             var minutes = now.getminutes();             var seconds = now.getseconds();              // format hours, minutes , seconds             if (hours < 10) {                 hours = "0" + hours;             }             if (minutes < 10) {                 minutes = "0" + minutes;             }             if (seconds < 10) {                 seconds = "0" + seconds;             }              // gets element want inject clock             var elem = document.getelementbyid('clock');              // sets elements inner html value our clock data             elem.innerhtml = hours + ':' + minutes + ':' + seconds;         }     function start(){         setinterval('updateclock()', 200);     }     </script> 

the first function calculates milisecons want add, , second function "live clock". how implement first function second one, working result?

for adding hours, use sethours :

// gets current time  var = new date();    console.log("actual time:", now);    now.sethours(now.gethours() + 1)    console.log("actual time + 1 hour:", now);

for references: https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/date/sethours


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -