Convert seconds to HH-MM-SS with JavaScript?

前端 未结 30 2591
南旧
南旧 2020-11-22 10:05

How can I convert seconds to an HH-MM-SS string using JavaScript?

30条回答
  •  攒了一身酷
    2020-11-22 10:33

    For anyone using AngularJS, a simple solution is to filter the value with the date API, which converts milliseconds to a string based on the requested format. Example:

    Offer ends in {{ timeRemaining | date: 'HH:mm:ss' }}

    Note that this expects milliseconds, so you may want to multiply timeRemaining by 1000 if you are converting from seconds (as the original question was formulated).

提交回复
热议问题