Skip to content

Instantly share code, notes, and snippets.

@itsgoofer
Created April 11, 2011 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save itsgoofer/914569 to your computer and use it in GitHub Desktop.
Save itsgoofer/914569 to your computer and use it in GitHub Desktop.
The same function written two ways.
//Traditional Way
public function getClockFormat1(milliseconds:Number):String
{
var seconds:Number = milliseconds / 1000;
var m:int = 0;
if (seconds > 0) {
while (seconds > 59) {
m++;
seconds -= 60;
}
return String((m < 10 ? "0" : "") + m + ":" + (seconds < 10 ? "0" : "") + seconds);
}else{
return "00:00";
}
}
//My way
public function getClockFormat2(milliseconds:Number):String
{
var seconds:Number = milliseconds / 1000;
var hh:Number = Math.floor(seconds / 3600);
var mm:Number = Math.floor((seconds % 3600) / 60);
var ss:Number = Math.floor(seconds % 3600 % 60);
var cf:String = String((hh < 10 ? "0" + hh : hh) + ":" + (mm < 10 ? "0" + mm : mm) + ":" + (ss < 10 ? "0" + ss : ss));
return cf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment