Created
November 27, 2011 22:12
-
-
Save monkeycycle/1398263 to your computer and use it in GitHub Desktop.
JavaScript format Seconds value as Formatted Time 00:00:00
This file contains hidden or 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 formatSecondsAsTime(secs, format) { | |
var hr = Math.floor(secs / 3600); | |
var min = Math.floor((secs - (hr * 3600))/60); | |
var sec = Math.floor(secs - (hr * 3600) - (min * 60)); | |
if (hr < 10) { hr = "0" + hr; } | |
if (min < 10) { min = "0" + min; } | |
if (sec < 10) { sec = "0" + sec; } | |
if (hr) { hr = "00"; } | |
if (format != null) { | |
var formatted_time = format.replace('hh', hr); | |
formatted_time = formatted_time.replace('h', hr*1+""); // check for single hour formatting | |
formatted_time = formatted_time.replace('mm', min); | |
formatted_time = formatted_time.replace('m', min*1+""); // check for single minute formatting | |
formatted_time = formatted_time.replace('ss', sec); | |
formatted_time = formatted_time.replace('s', sec*1+""); // check for single second formatting | |
return formatted_time; | |
} else { | |
return hr + ':' + min + ':' + sec; | |
} | |
} |
00:00:00,000 ???
where days?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Variable hr will always be "00" in this code.
I think code in line 9 shoulde be
if (!hr) { hr = "00"; }