Skip to content

Instantly share code, notes, and snippets.

@mallowigi
Last active August 29, 2015 14:01
Show Gist options
  • Save mallowigi/d409bfd8ab18958facb6 to your computer and use it in GitHub Desktop.
Save mallowigi/d409bfd8ab18958facb6 to your computer and use it in GitHub Desktop.
millisecondsToHMS
millisecondsToHMS: (ms) ->
hms = {
h: Math.floor(ms/(60*60*1000)),
m: Math.floor((ms/60000) % 60),
s: Math.floor((ms/1000) % 60)
}
tc = []
tc.push(hms.h) if (hms.h > 0)
m = hms.m;
mPrefix = ""
sPrefix = ""
mPrefix = "0" if hms.m < 10 && hms.h > 0
sPrefix = "0" if hms.s < 10
tc.push(mPrefix + hms.m)
tc.push(sPrefix + hms.s)
tc.join('.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment