setHours()

sethours() can fix the hours part of date function of JavaScript. We can set the hours from 0 to 23. This can only work on date object. Here is the sample code.
var dt= new Date();
document.write(dt + "<br><br>");
dt.setHours(2);
document.write(dt);
The output is here

We can set the hours value to previous value also by using negative value . Just change the this line in above code.
dt.setHours(-2);
The output is here

We can set the hours value to beyond 23 hours also. Here is one example.
dt.setHours(25);
Output is here

We have seen by using sethours we can fix the hours part to any value. This value is independent of present hours value. Try to display the date and time with hours value to display time after two hours from present value ( after reading the present hour ) .
To do this we have to read the present hours part and then add two hours to it. For this new value of hours we have to use sethours function the date object.
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