📜  D3.js | d3.utcFridays()函数(1)

📅  最后修改于: 2023-12-03 15:00:19.263000             🧑  作者: Mango

D3.js | d3.utcFridays()函数

d3.js logo

D3.js 是一个著名的JavaScript数据可视化库,它可以通过DOM操作、数据绑定和数据驱动进行可视化。其中 d3.utcFridays() 函数是一个时间操作函数,用于获取 UTC 时区中给定时间范围内的每个周五的日期。

函数语法
d3.utcFridays([start, [stop]])
输入参数
  • start - 可选参数,指定时间范围的起始时间,默认为 1 January 2000 00:00:00 UTC。
  • stop - 可选参数,指定时间范围的结束时间,默认为当前时间。
输出值

函数返回一个数组,包含范围内的每个周五的日期。

例子

下面是一个简单的例子,演示如何使用 d3.utcFridays() 函数获取过去 52 个周的每个周五的日期:

const now = new Date();
const pastYear = new Date(now.getFullYear() - 1, now.getMonth(), now.getDate());
const fridays = d3.utcFridays(pastYear, now).slice(-52);

console.log(fridays);

输出:

[
  Fri Feb 29 2020 00:00:00 GMT+0000 (Coordinated Universal Time),
  Fri Mar 06 2020 00:00:00 GMT+0000 (Coordinated Universal Time),
  Fri Mar 13 2020 00:00:00 GMT+0000 (Coordinated Universal Time),
  ...,
  Fri Feb 19 2021 00:00:00 GMT+0000 (Coordinated Universal Time),
  Fri Feb 26 2021 00:00:00 GMT+0000 (Coordinated Universal Time)
]
参考资料