Formatting the Date and Time
Explore how D3.js handles various date and time formats and learn to use the d3.timeParse function to convert diverse date strings into usable data for your visualizations. Understand how correct parsing can dynamically adjust time scales on graphs, improving the accuracy and clarity of your charts.
We'll cover the following...
Why we need different formats
One of the glorious things about the world is that we all do things a bit differently. One of those things is how we refer to dates and time.
In my neck of the woods, it’s customary to write the date as day - month – year, e.g., 23-12-2012. But in the United States, the more common format would be 12-23-2012. Likewise, the data may be in formats that name the months or weekdays (e.g., January and Tuesday) or combine dates and time together (e.g., 2012-12-23 15:45:32). So if we were to attempt to load in some data and try to get D3 to recognize it as date/time information, we really need to tell it what format the date/time is in.
You might be asking yourself: “What’s the point?” All we want to do is give it a number, and it can sort it out somehow. Well, that is true, but if we want to really bring out the best in our data and keep maximum flexibility ...