Jetzt ist es tatsächlich mal erforderlich gewesen, für ein Flash-Projekt Videospieldauern im Format HH:MM:SS (Bsp.: 01:37:25) auszugeben, die ursprünglich in Form von Sekunden vorliegt. Hier meine Herangehensweise in plain old ActionScript.
| 01 | function getFormattedTime(timeInSeconds) { |
| 02 | var hours = 0; |
| 03 | var minutes = 0; |
| 04 | var seconds = 0; |
| 05 | var hourOutput = ""; |
| 06 | var minOutput = ""; |
| 07 | var secOutput = ""; |
| 08 | var output = ""; |
| 09 | |
| 10 | hours = Math.floor(timeInSeconds/3600); |
| 11 | minutes = Math.floor((timeInSeconds-(hours*3600))/60); |
| 12 | seconds = Math.floor((timeInSeconds-(hours*3600))%60); |
| 13 | |
| 14 | if (hours<10) { |
| 15 | hourOutput = "0"+hours; |
| 16 | } else { |
| 17 | hourOutput = hours; |
| 18 | } |
| 19 | |
| 20 | if (minutes<10) { |
| 21 | minOutput = "0"+minutes; |
| 22 | } else { |
| 23 | minOutput = minutes; |
| 24 | } |
| 25 | |
| 26 | if (seconds<10) { |
| 27 | secOutput = "0"+seconds; |
| 28 | } else { |
| 29 | secOutput = seconds; |
| 30 | } |
| 31 | |
| 32 | output = hourOutput+":"+minOutput+":"+secOutput; |
| 33 | return output; |
| 34 | } |
| 35 | |
| 36 | trace(getFormattedTime(5845)); |