Set the hour for a specified date according to universal time?


JavaScript date setUTCHours() method sets the hour for a specified date according to local time. The following is the parameter for setUTCHours(hoursValue[, minutesValue[, secondsValue[, msValue]]]) −

  • hoursValue − An integer between 0 and 23, representing the hour.
  • minutesValue − An integer between 0 and 59, representing the minutes.
  • secondsValue − An integer between 0 and 59, representing the seconds. If you specify the secondsValue parameter, you must also specify the minutesValue.
  • msValue − A number between 0 and 999, representing the milliseconds. If you specify the msValue parameter, you must also specify the minutesValue and secondsValue.

Example

You can try to run the following code to set the hour for a specified date according to universal time −

<html>
   <head>
      <title>JavaScript setUTCHours Method</title>
   </head>
   <body>
      <script>
         var dt = new Date( "Aug 28, 2008 23:30:00" );
         dt.setUTCHours( 15 );
         
         document.write( dt );
      </script>
   </body>
</html>

Updated on: 23-Jun-2020

45 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements