ActionScript 3.0 + Calculate timespan between two dates?

后端 未结 7 1726
礼貌的吻别
礼貌的吻别 2020-12-01 10:00

In ActionScript 3.0, is there an automatic way to calculate the number of days, hours, minutes and seconds between two specified dates?

Basicly, what I need is the A

7条回答
  •  甜味超标
    2020-12-01 10:16

    for some a single function like this my be preferable... [condensed from Richard Szalay's code]

    public function timeDifference(startTime:Date, endTime:Date) : String
    {
    if (startTime == null) { return "startTime empty."; }
    if (endTime   == null) { return "endTime empty."; }
    var aTms = Math.floor(endTime.valueOf() - startTime.valueOf());
    return "Time taken:  "  
        + String( int(aTms/(24*60*+60*1000))     ) + " days, "
        + String( int(aTms/(    60*60*1000)) %24 ) + " hours, "
        + String( int(aTms/(       60*1000)) %60 ) + " minutes, "
        + String( int(aTms/(        1*1000)) %60 ) + " seconds.";
    }
    

提交回复
热议问题