如何获得以毫秒为单位的选定日期?

我想要ISO 8601 UTC格式(%Y-%m-%dT%H:%M:%S.%LZ)

let e = d3.event.selection.map(x3.invert);
let s = d3.event.selection || x3.range();
console.log(e[0], e[1]);
console.log(s[0], s[1]);

// Sun Jul 23 2017 13:32:33 GMT-0300 (-03) Fri Oct 13 2017 08:27:54 GMT-0300 (-03)
// 1037.59375 1040.59375


current format

我正在使用timeParse函数生成线和点:

parseDate = d3.timeParse("%Y-%m-%dT%H:%M:%S.%LZ");


来自数据对象:

lines: [[[1467341999153,0,5],5,10,15,20,25,30,35,40,45,50,60,70,...
// The first point of each line is an array:
// [unix epoch (milliseconds), Y Value, interval (milliseconds) between each point of the line]


从数据对象将Millis格式化为ISOString的函数

let calcDate = function(baseDate, frequencyDate, dateMultiplier) {
     let _ms = baseDate+(frequencyDate*dateMultiplier);
     let _date = new Date(_ms);
     return _date.toISOString()
}


let lineFunction = d3.line()
    .defined(function(d) { return d; })
    .x(function(d,i) {
          if (Array.isArray(d)) {
               _dateMultiplier = 0;
               _frequencyDate = d[2];
               _baseDate = d[0];
               return x(parseDate(calcDate(_baseDate, _frequencyDate, _dateMultiplier)))
          } else {
               _dateMultiplier++;
               return x(parseDate(calcDate(_baseDate, _frequencyDate, _dateMultiplier)))
          };
    })


谢谢!

最佳答案

解决了!非常简单!只是使用.toISOString()进行隐蔽

console.log(e [0] .toISOString(),e [1] .toISOString());

谢谢

关于javascript - d3js v4-笔刷精度,如何获得毫秒,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48342275/

10-13 00:34