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.
Change the Minute part of the date object → ← Date Reference ← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
plus2net.com
✖
We use cookies to improve your browsing experience. . Learn more