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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
