Remove leading zero from d3.js timeFormat

Viewed 1090

I'm working with d3.js and I'm using this documentation.

I use this to show the hour: %I:%M which shows the hour like 02:34.

Is there a way to remove the leading zero, in this case showing the data as 2:34 ?

2 Answers

As outlined in the documentation, the default padding is zero-padding for all directives except %e (for which it is space-padding).
To change the padding type, you can append a modifier to %:

  • 0 - zero-padding
  • _ - space-padding
  • - - disable padding

So, given your example: %-I:%M.

%-I will get rid of the leading zero.

Related