我试图理解datetime parsing在 D3.js 中。
为什么以下不起作用?它一直给我Uncaught TypeError: Object 2012-06-01 12:00:00+0000 has no method 'getFullYear
。
var parseDate = d3.time.format("%Y-%m-%d %H:%M:%S+%Z");
var datestr = '2012-06-01 12:00:00+0000';
console.log('d.datestr', datestr, typeof datestr);
console.log(parseDate(datestr));
JSFiddle在这里:http://jsfiddle.net/EBj9Z/
最佳答案
两个问题:
要解析日期,您需要使用 format.parse :
var format = d3.time.format("%Y-%m-%d");
format.parse("2011-01-01"); // returns a Date
format(new Date(2011, 0, 1)); // returns a string
The %Z directive (time zone offset, such as "-0700") is not yet supported for parsing.
关于javascript - D3日期解析: Uncaught TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18830857/