The multi-scale time format isn’t exposed as a public API outside of the standard one returned by a d3.time.scale’s tickFormat method.
That said, the implementation itself is fairly simple, so you could create your own multi-scale time format without a lot of work. The multi-scale time format is simply an ordered array of time formats, each of which has an associated test function. The first test function that returns true determines which time format is used.
The time format used by d3.time.scale has the following formats (taken from time/scale.js), specified in reverse order:
[".%L", function(d) { return d.getMilliseconds(); }],
[":%S", function(d) { return d.getSeconds(); }],
["%I:%M", function(d) { return d.getMinutes(); }],
["%I %p", function(d) { return d.getHours(); }],
["%a %d", function(d) { return d.getDay() && d.getDate() != 1; }],
["%b %d", function(d) { return d.getDate() != 1; }],
["%B", function(d) { return d.getMonth(); }],
["%Y", d3_true]
So, for example, if the time has a non-zero milliseconds field, then the ".%L" format is used; otherwise, if it has a non-zero seconds field, then ":%S" is used; and so on.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…