当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


d3.js d3.utcWednesdays()用法及代码示例


D3.js中的d3.utcWednesdays()函数用于返回协调世界时(UTC)中给定开始日期和结束日期范围内基于星期三的所有日期。

用法:

d3.utcWednesdays(start, end, step);

参数:该函数接受以下三个参数:


  • Start:此参数保存给定的开始日期。
  • end:此参数保存给定的结束日期。
  • step:这是用于跳过日期的可选值。

返回值:此函数返回基于协调世界时(UTC)的星期三的所有日期。

以下程序说明了D3.js中的d3.utcWednesdays()函数:

范例1:

<!DOCTYPE html> 
<html> 
   <head> 
      <title> 
          D3.js | d3.utcWednesdays() Function 
      </title> 
      <script src = 
          "https://d3js.org/d3.v4.min.js"> 
      </script> 
   </head> 
   
   <body> 
         
      <script> 
         
         // Initialising start and end date 
         var start = new Date(2015, 07, 01); 
         var end = new Date(2015, 07, 30); 
           
         // Calling the utcWednesdays() function 
         // without step value 
         var a = d3.utcWednesdays(start, end); 
           
         // Getting the Wednesday dates 
         console.log(a); 
      </script> 
   </body> 
</html>

输出:

["2015-08-05T00:00:00.000Z","2015-08-12T00:00:00.000Z",
 "2015-08-19T00:00:00.000Z","2015-08-26T00:00:00.000Z"]

范例2:

<!DOCTYPE html> 
<html> 
   <head> 
      <title> 
          D3.js | d3.utcWednesdays() Function 
      </title> 
      <script src = 
          "https://d3js.org/d3.v4.min.js"> 
      </script> 
   </head> 
   
   <body> 
         
      <script> 
         
         // Initialising start and end date 
         var start = new Date(2015, 07, 01); 
         var end = new Date(2015, 07, 30); 
           
         // Calling the utcWednesdays() function 
         // with step value 
         var a = d3.utcWednesdays(start, end, 2); 
           
         // Getting the Wednesday dates 
         console.log(a); 
      </script> 
   </body> 
</html>

输出:

["2015-08-05T00:00:00.000Z","2015-08-19T00:00:00.000Z"]

参考: https://devdocs.io/d3~5/d3-time#timeWednesdays



相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 D3.js | d3.utcWednesdays() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。