TimeDelta class in ActionScript?

Is there any ActionScript class that represents "time durations" similar to Python's TimeDelta class?

Edit : Thanks for the answers. I should clarify though: I want to be able to ask questions such as "how many weeks are between date and date1" or "let it x

represent" one day. "What is date2 + x

?"

I know I can do all this by representing dates as timestamps ... But I hope to find something nicer.

0


a source to share


4 answers


I've posted a complete AS3 port of the .NET TimeSpan class on this question , which sounds exactly like what you want.



// 5 days from new
var ts : TimeSpan = TimeSpan.fromDays(5);
var now : Date = new Date();
var fiveDaysTime : Date = ts.add(now);

// Diff between dates
var d1 : Date = new Date(2009, 1, 1);
var d2 : Date = new Date(2009, 1, 6);
var ts : TimeSpan = TimeSpan.fromDates(d1, d2);

      

+1


a source


You can use time () in Date class to get unix epoch milliseconds and use that for time delta.



+1


a source


If you subtract two dates:

var dateDiff = date1 - date2;

      

dateDiff will hold the number of milliseconds between two dates. Then you can convert from milliseconds to any usable number you like.

+1


a source


I don't think there is a class that measures changes over time in ActionScript 3. According to this ActionScript Adventures blog post , timing is very inaccurate in the Flash player on the web. This post is quite informative and has a SuperTimer class that can help you. You might want to account for this inaccuracy if you use solutions created by Justin Nissner and Tosti.

+1


a source







All Articles