Get started with d3-time-format CDN

BSD-3-Clause licensed

D3.js library for parsing, formatting dates and durations.

Tags:
  • d3
  • d3-module
  • time
  • format
  • strftime
  • strptime

Stable version

Copied!

How to start using d3-time-format CDN


// Include D3 and the time format plugin
const script = document.createElement('script');
script.src = 'https://cdn.cdnhub.io/d3-time-format/4.1.0/d3-time-format.min.js';
document.head.appendChild(script);

// Wait for D3 to be loaded
Promise.all([
  d3.json('data.json'),
  d3.ready(d3 => {
    d3.timeFormat("%Y-%m-%d %H:%M:%S"); // Initialize time format
  })
]).then(() => {

  // Parse and format time
  const parseTime = d3.timeParse("%Y-%m-%d %H:%M:%S");
  const formattedTime = d3.timeFormat("%Y-%m-%d %H:%M:%S")(new Date());

  // Use the parsed and formatted time in your data processing or visualization
  console.log(`Parsed: ${parseTime(formattedTime)}`);
});

All versions