1

Here I a building the time from seconds (50400) and this works great, however where the time is, for example 14:00, it only displays 14:0. I am trying to add a trailing zero.

I have already tried value = parseFloat(buildEndTime).toFixed(2); which doesn't work in this instance.

buildEndTime = Math.floor(gig.end_time/(60 * 60)) + ':' + Math.floor(gig.end_time / 60) % 60;
Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
Jake
  • 23
  • 3
  • You need *leading* zeroes, not trailing zeroes. E.g. `14:01` – Barmar Feb 07 '23 at 18:05
  • You need to adjust just the minute, not the entire time string. (Although for 24hr time I prefer leading zeros on the hour as well.) – Dave Newton Feb 07 '23 at 18:05
  • buildEndTime = Math.floor(gig.end_time/(60 * 60)) + ':' + (Math.floor(gig.end_time / 60) % 60 < 10 ? '0' : '') + Math.floor(gig.end_time / 60) % 60; **This checks if the minutes component is less than 10, and if it is, adds a zero in front of it** – AR Riyad Feb 07 '23 at 18:09
  • Thank you all for your input, as you say leading zeros on the minutes only is what I was looking for – Jake Feb 21 '23 at 16:24

0 Answers0