D3 在格式化时间时添加 19 小时
D3 adding 19 hours when it formats time
我正在尝试将数据库返回的以秒为单位的值转换为日期对象,然后将其传递给 D3 格式方法。但是当我尝试格式化时,d3 的格式化功能使我的时间增加了 19 个小时!例如,将 0 传递给日期对象,如下所示:
// create the third column for each segment.
tr.append("td").attr("class",'legendFreq')
.text(function(d){ return d3.time.format("%H:%M:%S")(new Date(0));});
returns 19:0:0
有人知道这里发生了什么吗?
d3 没有添加小时数,差异基于时区。
new Date(0)
默认情况下 returns 依赖于时区的日期对象。
(对我来说是Thu Jan 01 1970 01:00:00 GMT+0100 (W. Europe Standard Time)
)
如果我使用您的 d3.format 函数,我只会(正确地)得到小时部分:"01:00:00"
.
要使时间戳与时区无关,您应该使用 d3.time.format.utc 函数。使用它,我得到 "00:00:00"
:
d3.time.format.utc("%H:%M:%S")(new Date(0))
我正在尝试将数据库返回的以秒为单位的值转换为日期对象,然后将其传递给 D3 格式方法。但是当我尝试格式化时,d3 的格式化功能使我的时间增加了 19 个小时!例如,将 0 传递给日期对象,如下所示:
// create the third column for each segment.
tr.append("td").attr("class",'legendFreq')
.text(function(d){ return d3.time.format("%H:%M:%S")(new Date(0));});
returns 19:0:0
有人知道这里发生了什么吗?
d3 没有添加小时数,差异基于时区。
new Date(0)
默认情况下 returns 依赖于时区的日期对象。
(对我来说是Thu Jan 01 1970 01:00:00 GMT+0100 (W. Europe Standard Time)
)
如果我使用您的 d3.format 函数,我只会(正确地)得到小时部分:"01:00:00"
.
要使时间戳与时区无关,您应该使用 d3.time.format.utc 函数。使用它,我得到 "00:00:00"
:
d3.time.format.utc("%H:%M:%S")(new Date(0))