Home > Article > Web Front-end > Introduction to the use of setHours() method in JavaScript_Basic knowledge
The javascript Date.setHours() method sets the hours on the specified date according to local time.
Grammar
Date.setHours(hoursValue[, minutesValue[, secondsValue[, msValue]]])
Note: Parameters in brackets are optional
Here are the details of the parameters:
If the minutesValue, secondsValue and msValue parameters are not specified, the values returned by the getUTCMinutes, getUTCSeconds and getMilliseconds methods are used
Return value:
Example:
<html> <head> <title>JavaScript setHours Method</title> </head> <body> <script type="text/javascript"> var dt = new Date( "Aug 28, 2008 23:30:00" ); dt.setHours( 02 ); document.write( dt ); </script> </body> </html>
This will produce the following results:
Thu Aug 28 02:30:00 UTC+0530 2008