Epoch in ActionScript
A common requirement in programs is getting the number of seconds, milliseconds, or nanoseconds since the Unix epoch. Here’s how to do it in ActionScript.
Use new Date().time
to get the current time in milliseconds since the Unix epoch. ActionScript doesn’t have built-in methods for Unix time in seconds or nanoseconds, so we need to perform some calculations.
To run this ActionScript code, you would typically compile it into a SWF file and run it in a Flash Player or AIR runtime environment. The output would look something like this:
Note that ActionScript’s Date
class doesn’t provide nanosecond precision, so we’ve used microseconds (multiplying milliseconds by 1000) as the closest alternative.
Next, we’ll look at another time-related task: time parsing and formatting.