Search code examples
actionscript-3apache-flexadobeflash-builder

How to transform seconds in minutes ? in Flex


My problems is that I have this value...75 seconds and I want to display in my Grid like 1:15 minutes... How can I do this ?

I'm trying this...

    xmlCttSemAcao = new XMLListCollection(event.result..CTT);
    var i:int = 0;

    for each(var node:XML in xmlCttSemAcao)
    {
        xmlCttSemAcao[i].@DUR_CTT = (xmlCttSemAcao[i].@DUR_CTT / 60) %60;
        i++;
    }

    xmlCttSemAcao.refresh();
    gp2.refresh();

But my result for this example is: 1:25

Another example...56 seconds is displaying 0.933333


Solution

  • First, split it up a bit, then calculate seconds and minutes before putting them together:

    for each(var node:XML in xmlCttSemAcao)
    {
        var durCtt:int = xmlCttSemAcao[i].@DUR_CTT;
        var seconds:int = durCtt % 60;
        var minutes:int = durCtt / 60;
        var timeDisplay:String = minutes + ":" + seconds;
        xmlCttSemAcao[i].@DUR_CTT = timeDisplay;
        i++;
    }