8

I'd like to display a chrono of elapsed time since the beginning of an operation to a user. I create a Duration instance from a number of seconds, but then, I can't find a way to properly format it like 00:00:23. Do I have to manually get each time component (hours, minutes, seconds) and assemble them?

The Formatting section of the docs specifies that a DateTimeFormatter can only be passed to the format method of LocalDate, LocalTime, LocalDateTime, or ZonedDateTime instance, and Duration does not have such method.

DSav
  • 903
  • 1
  • 9
  • 11
  • Have you been able to find a way to format js-joda durations? I'm struggling with the same thing currently. – KareemJ Sep 26 '20 at 20:21
  • If I remember well, I had created my own function to format a duration. However, I haven't used `js-joda` since then. – DSav Sep 28 '20 at 11:36
  • What stack are you using? In my case, I was using spring on the backend and eventually found a way to allow the backend to take over the formatting part instead of jQuery. However, I'm still interested in seeing other solutions to this issue. – KareemJ Sep 28 '20 at 14:03
  • Initially, I was using MomentJS, but for my last big project, I decided to go with DayJS, a drop-in replacement with immutability and modularity. It suits my needs pretty well! – DSav Sep 29 '20 at 00:46

0 Answers0