Home  >  Article  >  Web Front-end  >  Set the hour of a specified date based on UTC?

Set the hour of a specified date based on UTC?

WBOY
WBOYforward
2023-09-02 19:49:16676browse

Set the hour of a specified date based on UTC?

JavaScript date setUTCHours() method sets the hour of the specified date based on local time. The following is the parameter list of setUTCHours(hoursValue[, minutesValue[, secondsValue[, msValue]]]):

  • hoursValue − an integer between 0 and 23, Indicates the hour.
  • minutesValue − An integer between 0 and 59 representing minutes.
  • secondsValue − An integer between 0 and 59 representing seconds. If the secondsValue parameter is specified, minutesValue must also be specified.
  • msValue − A number between 0 and 999 representing milliseconds. If the msValue parameter is specified, both minutesValue and secondsValue must be specified.

Example

You can try running the following code to set the hour of a specified date based on UTC:

<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>

The above is the detailed content of Set the hour of a specified date based on UTC?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete