I saw a lot of examples doing the same, but the d3.timeParse()
function just doesn't work as expected in my code and returns null
.
let parseDate = d3.timeParse("%Y-%m-%d");
let now = new Date();
console.log(now)//returns js date object
let parsedNow = parseDate(now);
console.log(parsedNow) //returns null
See this fiddle for running example.
Any Ideas what I'm doing wrong here?
Help would be greatly appreciated.
You are trying to parse a date object which is incorrect, I think you want to format a date object into "%Y-%m-%d"
so instead of this
let parseDate = d3.timeParse("%Y-%m-%d");//timeParse is incorrect
it should have been
let parseDate = d3.timeFormat("%Y-%m-%d");//timeFormat a date object into %Y-%m-%d
working code here