D3.js中的d3.utcHour函数用于返回协调世界时(UTC)中给定开始时间和结束时间范围内所有带有日期的小时。
用法:
d3.utcHour.range(start, end, step);
参数:该函数接受以下三个参数:
- Start:此参数保存给定的开始时间。
- end:此参数保存给定的结束时间。
- step:这是用于跳过小时的可选值。
返回值:此函数返回给定范围内所有可能的小时数。
以下示例程序旨在说明D3.js中的d3.utcHour函数:
示例1:
<!DOCTYPE html> 
<html> 
   <head> 
      <title> 
          D3.js | d3.utcHour Function  
      </title> 
      <script src = 
          "https://d3js.org/d3.v4.min.js"> 
      </script> 
   </head> 
   
   <body> 
         
      <script> 
         
         // Initialising start and end time 
         var start = new Date(2015, 07, 01, 4, 20); 
         var end = new Date(2015, 07, 01, 8, 20); 
           
         // Calling the utcHour function 
         // without step value 
         var a = d3.utcHour.range(start, end); 
           
         // Getting the hours values 
         console.log(a); 
      </script> 
   </body> 
</html>输出:
["2015-07-31T23:00:00.000Z", "2015-08-01T00:00:00.000Z", "2015-08-01T01:00:00.000Z", "2015-08-01T02:00:00.000Z"]
示例2:
<!DOCTYPE html> 
<html> 
   <head> 
      <title> 
          D3.js | d3.utcHour Function  
      </title> 
      <script src = 
          "https://d3js.org/d3.v4.min.js"> 
      </script> 
   </head> 
   
   <body> 
         
      <script> 
         
         // Initialising start and end time 
         var start = new Date(2015, 07, 01, 1, 20); 
         var end = new Date(2015, 07, 01, 6, 20); 
           
         // Calling the utcHour function 
         // with step value 
         var a = d3.utcHour.range(start, end, 2); 
           
         // Getting the hour values 
         console.log(a); 
      </script> 
   </body> 
</html>输出:
["2015-07-31T20:00:00.000Z", "2015-07-31T22:00:00.000Z", "2015-08-01T00:00:00.000Z"]
参考: https://devdocs.io/d3~5/d3-time#timeHour
相关用法
- p5.js cos()用法及代码示例
- d3.js d3.hsl()用法及代码示例
- p5.js log()用法及代码示例
- p5.js tan()用法及代码示例
- PHP pos()用法及代码示例
- d3.js d3.sum()用法及代码示例
- PHP key()用法及代码示例
- p5.js sin()用法及代码示例
- p5.js second()用法及代码示例
- PHP Ds\Map put()用法及代码示例
- PHP each()用法及代码示例
- PHP each()用法及代码示例
注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 D3.js | d3.utcHour Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
