d3.time.format中的时间格式

来源:互联网 发布:twitter视频保存软件 编辑:程序博客网 时间:2024/05/29 03:16
  • %a - abbreviated weekday name.
  • %A - full weekday name.
  • %b - abbreviated month name.
  • %B - full month name.
  • %c - date and time, as "%a %b %e %H:%M:%S %Y".
  • %d - zero-padded day of the month as a decimal number [01,31].
  • %e - space-padded day of the month as a decimal number [ 1,31]; equivalent to%_d.
  • %H - hour (24-hour clock) as a decimal number [00,23].
  • %I - hour (12-hour clock) as a decimal number [01,12].
  • %j - day of the year as a decimal number [001,366].
  • %m - month as a decimal number [01,12].
  • %M - minute as a decimal number [00,59].
  • %L - milliseconds as a decimal number [000, 999].
  • %p - either AM or PM.
  • %S - second as a decimal number [00,61].
  • %U - week number of the year (Sunday as the first day of the week) as a decimal number [00,53].
  • %w - weekday as a decimal number [0(Sunday),6].
  • %W - week number of the year (Monday as the first day of the week) as a decimal number [00,53].
  • %x - date, as "%m/%d/%Y".
  • %X - time, as "%H:%M:%S".
  • %y - year without century as a decimal number [00,99].
  • %Y - year with century as a decimal number.
  • %Z - time zone offset, such as "-0700".
  • %% - a literal "%" character.

<!DOCTYPE html><metacharset="utf-8"><style>.axistextfont:10px sans-serif;}.axisline,.axispath fill: none; stroke:#000;  shape-rendering: crispEdges;}</style><body><scriptsrc="http://d3js.org/d3.v3.min.js"></script><script>var customTimeFormat = timeFormat([  [d3.time.format("%Y"),function() {returntrue; }],  [d3.time.format("%B"),function(d) {return d.getMonth(); }],  [d3.time.format("%b %d"),function(d) {return d.getDate() !=1; }],  [d3.time.format("%a %d"),function(d) {return d.getDay() && d.getDate() !=1; }],  [d3.time.format("%I %p"),function(d) {return d.getHours(); }],  [d3.time.format("%I:%M"),function(d) {return d.getMinutes(); }],  [d3.time.format(":%S"),function(d) {return d.getSeconds(); }],  [d3.time.format(".%L"),function(d) {return d.getMilliseconds(); }]]);var margin = {top:250, right:40, bottom: 250, left: 40},    width = 960 - margin.left - margin.right,    height =500 - margin.top - margin.bottom;var x = d3.time.scale()    .domain([new Date(2012,0,1), new Date(2013,0, 1)])    .range([0, width]);var xAxis = d3.svg.axis()    .scale(x)    .tickFormat(customTimeFormat);var svg = d3.select("body").append("svg")    .attr("width", width + margin.left + margin.right)    .attr("height", height + margin.top + margin.bottom)  .append("g")    .attr("transform","translate(" + margin.left + "," + margin.top +")");svg.append("g")    .attr("class","x axis")    .attr("transform","translate(0," + height + ")")    .call(xAxis);functiontimeFormat(formats) { returnfunction(date) {   var i = formats.length -1, f = formats[i];   while (!f[1](date)) f = formats[--i];   return f[0](date);  };}</script>

 

http://bl.ocks.org/mbostock/4149176

http://www.verisi.com/resources/d3-tutorial-basic-charts.htm