ActionScript 3.0 + Calculate timespan between two dates?

后端 未结 7 1725
礼貌的吻别
礼貌的吻别 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:29

    You can covert the two date times into milliseconds since the epoch, perform your math and then use the resultant milliseconds to calculate these higher timespan numbers.

    var someDate:Date = new Date(...);
    var anotherDate:Date = new Date(...);
    var millisecondDifference:int = anotherDate.valueOf() - someDate.valueOf();
    var seconds:int = millisecondDifference / 1000;
    ....
    

    The LiveDocs are useful for this type of thing too. Sorry if the ActionScript is a bit off, but it has been a while.

    I'd also recommend creating a set of static class methods that can perform these operations if you're doing a lot of this type of math. Sadly, this basic functionality doesn't really exist in the standard APIs.

提交回复
热议问题