Untitled UI logotext
Solutions
WebsitesEcommerceMobile AppsWeb AppsProduction Support & Maintenance
Our work
Company
About usBlogPodcastContact us
Book a free consultation

How To Convert Seconds to Minutes in ActionScript 3

Olivia Rhye

Recently, I've been developing a game in ActionScript 3 (which I'll share later). I needed to have a second timer count down, which is easy enough with the Timer class. The hard part for me was formatting it so it made sense to the player. Here's what I came up with for converting a second count to minutes (formatted string):


public function convertSecondsToMinutes(seconds:Number):String
{
var secondsString:String = new String;

if (this.time%60 < 10) // checks to see if it needs a leading zero
{
secondsString = "0" + this.time%60;
}
else
{
secondsString = "" + this.time%60;
// the double quotes are needed to cast this as a string
}
var minutes:String=Math.floor(this.time/60) + ':' + secondsString;

return minutes;
}

Ready to start a project?

Book a free consultation
Untitled UI logotext
Our work
About us
Blog
Careers
Submit a ticket
Agency Partnerships
Contact
© 2024 fjorge. All rights reserved.
Privacy