Table of Contents

Date( ) Global Function Flash 5

a string representing the current date and time
Date()

Returns

A string containing the current date and time.

Description

The Date( ) function returns a human-readable string that expresses the current date and local time. The string also includes the GMT offset (the number of hours difference between local time and Greenwich Mean Time).

Be sure not to confuse the global Date( ) function with the Date( ) class constructor. The Date( ) function returns the date formatted as a standard, if terse, string. It is convenient for humans but not very useful inside a program where you need to manipulate dates and times. For that purpose, you are better off using objects of the Date class, which allow convenient independent access to the year, month, day, and time.

Example

To place the current time and date in a text field with minimal fuss, we can use the Date( ) function as follows:

someMovieClip.createTextField("output_txt", 1, 0, 0, 200, 20);
output_txt.text = Date();
   
// Sets the displayed text to a string formatted as follows:
// "Mon Aug 28 16:23:09 GMT-0400 2000"

Reader Exercise: Modify the preceding example using String.substring( ) to show the date and time (including the hours and minutes), but eliminate the seconds and GMT offset from the display. See the Example in the Date class entry for a much more flexible approach.

See Also

The Date class, Date.UTC( )


Table of Contents