Created
August 3, 2015 15:44
-
-
Save austbot/0c49a2809ec0cc694d08 to your computer and use it in GitHub Desktop.
Format Moment Duration easily
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function (duration, format) { | |
//Setup time | |
var hours = duration.hours(), | |
minutes = duration.minutes(), | |
seconds = duration.seconds(); | |
//Iterate the format | |
formatStr = format; | |
//Replace format keys | |
formatStr = formatStr.replace(/hh:/, hours > 0 ? hours + ":" : ''); | |
formatStr = formatStr.replace(/mm:/, minutes > 0 ? minutes + ":" : ''); | |
formatStr = formatStr.replace(/ss/, seconds > 0 ? seconds : '0'); | |
return formatStr; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can u give a quick example on how to use this please ? the format is confusing..