You want to know the current date and time.
Create a new date by using the Date() constructor with no parameters. Alternatively, use a CGI script or any other server-side program to return the server time and create a new Date object from that value.
The date and time that ActionScript calculates on its own is based on the client computer’s date and time settings. Therefore, if the user’s computer has the incorrect time, so will the Date object. With that caveat in mind, you can retrieve the current client-side date and time by creating a new Date object by using a constructor without parameters, as follows:
// Create a new
Dateobject. var current:Date = new Date(); // Displays client-side date and time. trace(current);
If you have an Internet connection, the Flash movie attempts to retrieve the date and time from a server. This technique can ensure more accurate dates and times. Although the server’s time settings might be inaccurate, at least the time will be consistent for all clients.
The basic process when reading the time from a server is as follows:
Create a CGI script on the web server that outputs the number of seconds since midnight of January 1, 1970 (the epoch).
Use a flash.net.URLLoader object from ActionScript to load the epoch seconds.
Convert the loaded seconds from a string to a number, multiply by 1,000, and construct a new Date object by passing the value to the constructor.
PHP is a scripting language that can ...