Richard
Richard

Reputation: 65600

D3 date parsing: Uncaught TypeError

I'm trying to understand datetime parsing in D3.js.

Why isn't the following working? It keeps giving me 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 here: http://jsfiddle.net/EBj9Z/

Upvotes: 2

Views: 3026

Answers (1)

Adam Pearce
Adam Pearce

Reputation: 9293

Two issues:

To parse a date, you need to use 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

Additionally:

The %Z directive (time zone offset, such as "-0700") is not yet supported for parsing.

Upvotes: 2

Related Questions