{"action":"created","issue":{"url":"https://api.github.com/repos/moment/moment/issues/1048","labels_url":"https://api.github.com/repos/moment/moment/issues/1048/labels{/name}","comments_url":"https://api.github.com/repos/moment/moment/issues/1048/comments","events_url":"https://api.github.com/repos/moment/moment/issues/1048/events","html_url":"https://github.com/moment/moment/issues/1048","id":19008383,"number":1048,"title":"duration formatting","user":{"login":"mj1856","id":1396388,"avatar_url":"https://avatars.githubusercontent.com/u/1396388?v=3","gravatar_id":"","url":"https://api.github.com/users/mj1856","html_url":"https://github.com/mj1856","followers_url":"https://api.github.com/users/mj1856/followers","following_url":"https://api.github.com/users/mj1856/following{/other_user}","gists_url":"https://api.github.com/users/mj1856/gists{/gist_id}","starred_url":"https://api.github.com/users/mj1856/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mj1856/subscriptions","organizations_url":"https://api.github.com/users/mj1856/orgs","repos_url":"https://api.github.com/users/mj1856/repos","events_url":"https://api.github.com/users/mj1856/events{/privacy}","received_events_url":"https://api.github.com/users/mj1856/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/moment/moment/labels/New%20Feature","name":"New Feature","color":"bfe5bf"},{"url":"https://api.github.com/repos/moment/moment/labels/todo","name":"todo","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":41,"created_at":"2013-09-04T22:51:59Z","updated_at":"2015-09-08T03:49:12Z","closed_at":null,"body":"We've touched on this before in #463 and #879 but never really talked about it directly in its own issue.\r\n\r\nWe need a method for formatting durations similar to how we format dates.   It should be as simple as:\r\n\r\n```javascript\r\nmoment.duration(x).format(\"H:mm:ss\")\r\n```\r\n\r\nNote that the formatting tokens would have to carry slightly different meaning, since we're representing an elapsed duration of time, rather than a time-of-day.  I suggest the following:\r\n\r\n- `hh` would mean \"hours remainder after accounting for days\"\r\n- `h` would be the single digit form of `hh`\r\n- `HH` would mean \"total whole hours\"\r\n- `H` would be the single digit form of `HH`\r\n- `HHH` would mean \"total hours including decimals\" - although that can currently be done with `duration.asHours()`, so this might not be necessary.\r\n\r\nSimilar formatting would apply for other units.  In this context, the highest unit would be a \"day\", which would be a standard day consisting of 24 standard hours.  It wouldn't make sense to measure years or months with this due to calendaring issues.\r\n\r\nNote, this came up recently (again) on StackOverflow in [this question](http://stackoverflow.com/q/18623783/634824).  The user was looking for something like `duration.format(\"H:mm:ss\")`.  This is the workaround:\r\n\r\n    Math.floor(duration.asHours()) + moment.utc(duration.asMilliseconds()).format(\":mm:ss\")\r\n\r\nThis works, but it feels hacky.  This should be built in.\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/moment/moment/issues/comments/138422487","html_url":"https://github.com/moment/moment/issues/1048#issuecomment-138422487","issue_url":"https://api.github.com/repos/moment/moment/issues/1048","id":138422487,"user":{"login":"johnculviner","id":1644353,"avatar_url":"https://avatars.githubusercontent.com/u/1644353?v=3","gravatar_id":"","url":"https://api.github.com/users/johnculviner","html_url":"https://github.com/johnculviner","followers_url":"https://api.github.com/users/johnculviner/followers","following_url":"https://api.github.com/users/johnculviner/following{/other_user}","gists_url":"https://api.github.com/users/johnculviner/gists{/gist_id}","starred_url":"https://api.github.com/users/johnculviner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnculviner/subscriptions","organizations_url":"https://api.github.com/users/johnculviner/orgs","repos_url":"https://api.github.com/users/johnculviner/repos","events_url":"https://api.github.com/users/johnculviner/events{/privacy}","received_events_url":"https://api.github.com/users/johnculviner/received_events","type":"User","site_admin":false},"created_at":"2015-09-08T03:49:12Z","updated_at":"2015-09-08T03:49:12Z","body":":+1:  surprised moment doesn't do this, usually it's never failed me!"}}