Adobe® Flex® 4 Language Reference
Show Packages and Classes List |  Packages  |  Classes  |  Index  |  Appendixes
__Global__ 
Date 
PackageTop Level
Classpublic final dynamic class Date
InheritanceDate Inheritance Object

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The Date class represents date and time information. An instance of the Date class represents a particular point in time for which the properties such as month, day, hours, and seconds can be queried or modified. The Date class lets you retrieve date and time values relative to universal time (Greenwich mean time, now called universal time or UTC) or relative to local time, which is determined by the local time zone setting on the operating system that is running Flash Player. The methods of the Date class are not static but apply only to the individual Date object specified when the method is called. The Date.UTC() and Date.parse() methods are exceptions; they are static methods.

The Date class handles daylight saving time differently, depending on the operating system and runtime version. Flash Player 6 and later versions handle daylight saving time on the following operating systems in these ways:

  • Windows - the Date object automatically adjusts its output for daylight saving time. The Date object detects whether daylight saving time is employed in the current locale, and if so, it detects the standard-to-daylight saving time transition date and times. However, the transition dates currently in effect are applied to dates in the past and the future, so the daylight saving time bias might calculate incorrectly for dates in the past when the locale had different transition dates.
  • Mac OS X - the Date object automatically adjusts its output for daylight saving time. The time zone information database in Mac OS X is used to determine whether any date or time in the present or past should have a daylight saving time bias applied.
  • Mac OS 9 - the operating system provides only enough information to determine whether the current date and time should have a daylight saving time bias applied. Accordingly, the date object assumes that the current daylight saving time bias applies to all dates and times in the past or future.

Flash Player 5 handles daylight saving time on the following operating systems as follows:

  • Windows - the U.S. rules for daylight saving time are always applied, which leads to incorrect transitions in Europe and other areas that employ daylight saving time but have different transition times than the U.S. Flash correctly detects whether daylight saving time is used in the current locale.

To use the Date class, construct a Date instance using the new operator.

ActionScript 3.0 adds several new accessor properties that can be used in place of many Date class methods that access or modify Date instances. ActionScript 3.0 also includes several new variations of the toString() method that are included for ECMA-262 3rd Edition compliance, including: Date.toLocaleString(), Date.toTimeString(), Date.toLocaleTimeString(), Date.toDateString(), and Date.toLocaleDateString().

To compute relative time or time elapsed, see the getTimer() method in the flash.utils package.

View the examples

See also



Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  date : Number
The day of the month (an integer from 1 to 31) specified by a Date object according to local time.
Date
  dateUTC : Number
The day of the month (an integer from 1 to 31) of a Date object according to universal time (UTC).
Date
  day : Number
[read-only] The day of the week (0 for Sunday, 1 for Monday, and so on) specified by this Date according to local time.
Date
  dayUTC : Number
[read-only] The day of the week (0 for Sunday, 1 for Monday, and so on) of this Date according to universal time (UTC).
Date
  fullYear : Number
The full year (a four-digit number, such as 2000) of a Date object according to local time.
Date
  fullYearUTC : Number
The four-digit year of a Date object according to universal time (UTC).
Date
  hours : Number
The hour (an integer from 0 to 23) of the day portion of a Date object according to local time.
Date
  hoursUTC : Number
The hour (an integer from 0 to 23) of the day of a Date object according to universal time (UTC).
Date
  milliseconds : Number
The milliseconds (an integer from 0 to 999) portion of a Date object according to local time.
Date
  millisecondsUTC : Number
The milliseconds (an integer from 0 to 999) portion of a Date object according to universal time (UTC).
Date
  minutes : Number
The minutes (an integer from 0 to 59) portion of a Date object according to local time.
Date
  minutesUTC : Number
The minutes (an integer from 0 to 59) portion of a Date object according to universal time (UTC).
Date
  month : Number
The month (0 for January, 1 for February, and so on) portion of a Date object according to local time.
Date
  monthUTC : Number
The month (0 [January] to 11 [December]) portion of a Date object according to universal time (UTC).
Date
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  seconds : Number
The seconds (an integer from 0 to 59) portion of a Date object according to local time.
Date
  secondsUTC : Number
The seconds (an integer from 0 to 59) portion of a Date object according to universal time (UTC).
Date
  time : Number
The number of milliseconds since midnight January 1, 1970, universal time, for a Date object.
Date
  timezoneOffset : Number
[read-only] The difference, in minutes, between universal time (UTC) and the computer's local time.
Date
Public Methods
 MethodDefined By
  
Date(yearOrTimevalue:Object, month:Number, date:Number = 1, hour:Number = 0, minute:Number = 0, second:Number = 0, millisecond:Number = 0)
Constructs a new Date object that holds the specified date and time.
Date
  
Returns the day of the month (an integer from 1 to 31) specified by a Date object according to local time.
Date
  
Returns the day of the week (0 for Sunday, 1 for Monday, and so on) specified by this Date according to local time.
Date
  
Returns the full year (a four-digit number, such as 2000) of a Date object according to local time.
Date
  
Returns the hour (an integer from 0 to 23) of the day portion of a Date object according to local time.
Date
  
Returns the milliseconds (an integer from 0 to 999) portion of a Date object according to local time.
Date
  
Returns the minutes (an integer from 0 to 59) portion of a Date object according to local time.
Date
  
Returns the month (0 for January, 1 for February, and so on) portion of this Date according to local time.
Date
  
Returns the seconds (an integer from 0 to 59) portion of a Date object according to local time.
Date
  
Returns the number of milliseconds since midnight January 1, 1970, universal time, for a Date object.
Date
  
Returns the difference, in minutes, between universal time (UTC) and the computer's local time.
Date
  
Returns the day of the month (an integer from 1 to 31) of a Date object, according to universal time (UTC).
Date
  
Returns the day of the week (0 for Sunday, 1 for Monday, and so on) of this Date according to universal time (UTC).
Date
  
Returns the four-digit year of a Date object according to universal time (UTC).
Date
  
Returns the hour (an integer from 0 to 23) of the day of a Date object according to universal time (UTC).
Date
  
Returns the milliseconds (an integer from 0 to 999) portion of a Date object according to universal time (UTC).
Date
  
Returns the minutes (an integer from 0 to 59) portion of a Date object according to universal time (UTC).
Date
  
Returns the month (0 [January] to 11 [December]) portion of a Date object according to universal time (UTC).
Date
  
Returns the seconds (an integer from 0 to 59) portion of a Date object according to universal time (UTC).
Date
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
  
[static] Converts a string representing a date into a number equaling the number of milliseconds elapsed since January 1, 1970, UTC.
Date
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
  
Sets the day of the month, according to local time, and returns the new time in milliseconds.
Date
  
Sets the year, according to local time, and returns the new time in milliseconds.
Date
  
setHours(hour:Number, minute:Number, second:Number, millisecond:Number):Number
Sets the hour, according to local time, and returns the new time in milliseconds.
Date
  
Sets the milliseconds, according to local time, and returns the new time in milliseconds.
Date
  
setMinutes(minute:Number, second:Number, millisecond:Number):Number
Sets the minutes, according to local time, and returns the new time in milliseconds.
Date
  
Sets the month and optionally the day of the month, according to local time, and returns the new time in milliseconds.
Date
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
  
setSeconds(second:Number, millisecond:Number):Number
Sets the seconds, according to local time, and returns the new time in milliseconds.
Date
  
setTime(millisecond:Number):Number
Sets the date in milliseconds since midnight on January 1, 1970, and returns the new time in milliseconds.
Date
  
Sets the day of the month, in universal time (UTC), and returns the new time in milliseconds.
Date
  
Sets the year, in universal time (UTC), and returns the new time in milliseconds.
Date
  
setUTCHours(hour:Number, minute:Number, second:Number, millisecond:Number):Number
Sets the hour, in universal time (UTC), and returns the new time in milliseconds.
Date
  
Sets the milliseconds, in universal time (UTC), and returns the new time in milliseconds.
Date
  
setUTCMinutes(minute:Number, second:Number, millisecond:Number):Number
Sets the minutes, in universal time (UTC), and returns the new time in milliseconds.
Date
  
Sets the month, and optionally the day, in universal time(UTC) and returns the new time in milliseconds.
Date
  
setUTCSeconds(second:Number, millisecond:Number):Number
Sets the seconds, and optionally the milliseconds, in universal time (UTC) and returns the new time in milliseconds.
Date
  
Returns a string representation of the day and date only, and does not include the time or timezone.
Date
  
Returns a String representation of the day and date only, and does not include the time or timezone.
Date
  
Returns a String representation of the day, date, time, given in local time.
Date
  
Returns a String representation of the time only, and does not include the day, date, year, or timezone.
Date
  
Returns a String representation of the day, date, time, and timezone.
Date
  
Returns a String representation of the time and timezone only, and does not include the day and date.
Date
  
Returns a String representation of the day, date, and time in universal time (UTC).
Date
  
UTC(year:Number, month:Number, date:Number = 1, hour:Number = 0, minute:Number = 0, second:Number = 0, millisecond:Number = 0):Number
[static] Returns the number of milliseconds between midnight on January 1, 1970, universal time, and the time specified in the parameters.
Date
  
Returns the number of milliseconds since midnight January 1, 1970, universal time, for a Date object.
Date
Property Detail

date

property
date:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The day of the month (an integer from 1 to 31) specified by a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.



Implementation
    AS3 function get date():Number
    AS3 function set date(value:Number):void

See also

dateUTC

property 
dateUTC:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The day of the month (an integer from 1 to 31) of a Date object according to universal time (UTC).



Implementation
    AS3 function get dateUTC():Number
    AS3 function set dateUTC(value:Number):void

See also

day

property 
day:Number  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The day of the week (0 for Sunday, 1 for Monday, and so on) specified by this Date according to local time. Local time is determined by the operating system on which the Flash runtimes are running.



Implementation
    AS3 function get day():Number

See also

dayUTC

property 
dayUTC:Number  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The day of the week (0 for Sunday, 1 for Monday, and so on) of this Date according to universal time (UTC).



Implementation
    AS3 function get dayUTC():Number

See also

fullYear

property 
fullYear:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The full year (a four-digit number, such as 2000) of a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.



Implementation
    AS3 function get fullYear():Number
    AS3 function set fullYear(value:Number):void

See also

fullYearUTC

property 
fullYearUTC:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The four-digit year of a Date object according to universal time (UTC).



Implementation
    AS3 function get fullYearUTC():Number
    AS3 function set fullYearUTC(value:Number):void

See also

hours

property 
hours:Number

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0 Flash Player 9, Flash Lite 4

The hour (an integer from 0 to 23) of the day portion of a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.



Implementation
    AS3 function get hours():Number
    AS3 function set hours(value:Number):void

See also

hoursUTC

property 
hoursUTC:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The hour (an integer from 0 to 23) of the day of a Date object according to universal time (UTC).



Implementation
    AS3 function get hoursUTC():Number
    AS3 function set hoursUTC(value:Number):void

See also

milliseconds

property 
milliseconds:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The milliseconds (an integer from 0 to 999) portion of a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.



Implementation
    AS3 function get milliseconds():Number
    AS3 function set milliseconds(value:Number):void

See also

millisecondsUTC

property 
millisecondsUTC:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The milliseconds (an integer from 0 to 999) portion of a Date object according to universal time (UTC).



Implementation
    AS3 function get millisecondsUTC():Number
    AS3 function set millisecondsUTC(value:Number):void

See also

minutes

property 
minutes:Number

Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0 Flash Player 9, Flash Lite 4

The minutes (an integer from 0 to 59) portion of a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.



Implementation
    AS3 function get minutes():Number
    AS3 function set minutes(value:Number):void

See also

minutesUTC

property 
minutesUTC:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The minutes (an integer from 0 to 59) portion of a Date object according to universal time (UTC).



Implementation
    AS3 function get minutesUTC():Number
    AS3 function set minutesUTC(value:Number):void

See also

month

property 
month:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The month (0 for January, 1 for February, and so on) portion of a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.



Implementation
    AS3 function get month():Number
    AS3 function set month(value:Number):void

See also

monthUTC

property 
monthUTC:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The month (0 [January] to 11 [December]) portion of a Date object according to universal time (UTC).



Implementation
    AS3 function get monthUTC():Number
    AS3 function set monthUTC(value:Number):void

See also

seconds

property 
seconds:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The seconds (an integer from 0 to 59) portion of a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.



Implementation
    AS3 function get seconds():Number
    AS3 function set seconds(value:Number):void

See also

secondsUTC

property 
secondsUTC:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The seconds (an integer from 0 to 59) portion of a Date object according to universal time (UTC).



Implementation
    AS3 function get secondsUTC():Number
    AS3 function set secondsUTC(value:Number):void

See also

time

property 
time:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The number of milliseconds since midnight January 1, 1970, universal time, for a Date object. Use this method to represent a specific instant in time when comparing two or more Date objects.



Implementation
    AS3 function get time():Number
    AS3 function set time(value:Number):void

See also

timezoneOffset

property 
timezoneOffset:Number  [read-only]

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

The difference, in minutes, between universal time (UTC) and the computer's local time. Specifically, this value is the number of minutes you need to add to the computer's local time to equal UTC. If your computer's time is set later than UTC, the value will be negative.



Implementation
    AS3 function get timezoneOffset():Number

See also

Constructor Detail

Date

()Constructor
public function Date(yearOrTimevalue:Object, month:Number, date:Number = 1, hour:Number = 0, minute:Number = 0, second:Number = 0, millisecond:Number = 0)

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Constructs a new Date object that holds the specified date and time.

The Date() constructor takes up to seven parameters (year, month, ..., millisecond) to specify a date and time to the millisecond. The date that the newly constructed Date object contains depends on the number, and data type, of arguments passed.

  • If you pass no arguments, the Date object is assigned the current date and time.
  • If you pass one argument of data type Number, the Date object is assigned a time value based on the number of milliseconds since January 1, 1970 0:00:000 GMT, as specified by the lone argument.
  • If you pass one argument of data type String, and the string contains a valid date, the Date object contains a time value based on that date.
  • If you pass two or more arguments, the Date object is assigned a time value based on the argument values passed, which represent the date's year, month, date, hour, minute, second, and milliseconds.

If you pass a string to the Date class constructor, the date can be in a variety of formats, but must at least include the month, date, and year. For example, Feb 1 2005 is valid, but Feb 2005 is not. The following list indicates some of the valid formats:

  • Day Month Date Hours:Minutes:Seconds GMT Year (for instance, "Tue Feb 1 00:00:00 GMT-0800 2005", which matches toString())
  • Day Month Date Year Hours:Minutes:Seconds AM/PM (for instance, "Tue Feb 1 2005 12:00:00 AM", which matches toLocaleString())
  • Day Month Date Year (for instance, "Tue Feb 1 2005", which matches toDateString())
  • Month/Day/Year (for instance, "02/01/2005")
  • Month/Year (for instance, "02/2005")

Parameters
yearOrTimevalue:Object — If other parameters are specified, this number represents a year (such as 1965); otherwise, it represents a time value. If the number represents a year, a value of 0 to 99 indicates 1900 through 1999; otherwise all four digits of the year must be specified. If the number represents a time value (no other parameters are specified), it is the number of milliseconds before or after 0:00:00 GMT January 1, 1970; a negative values represents a time before 0:00:00 GMT January 1, 1970, and a positive value represents a time after.
 
month:Number — An integer from 0 (January) to 11 (December).
 
date:Number (default = 1) — An integer from 1 to 31.
 
hour:Number (default = 0) — An integer from 0 (midnight) to 23 (11 p.m.).
 
minute:Number (default = 0) — An integer from 0 to 59.
 
second:Number (default = 0) — An integer from 0 to 59.
 
millisecond:Number (default = 0) — An integer from 0 to 999 of milliseconds.

See also

Method Detail

getDate

()method
AS3 function getDate():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the day of the month (an integer from 1 to 31) specified by a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.

Returns
Number — The day of the month (1 - 31) a Date object represents.

See also


Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The getDate() method is then called, which retrieves the day of the month.
package {
    import flash.display.Sprite;

    public class DateExample extends Sprite {

        public function DateExample() {
            var someBirthday:Date = new Date(1974, 10, 30, 1, 20);
            trace(someBirthday);            // Sat Nov 30 01:20:00 GMT-0800 1974
            trace(someBirthday.getDate()); // 30
        }
    }
}

getDay

()method 
AS3 function getDay():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the day of the week (0 for Sunday, 1 for Monday, and so on) specified by this Date according to local time. Local time is determined by the operating system on which the Flash runtimes are running.

Returns
Number — A numeric version of the day of the week (0 - 6) a Date object represents.

Example  ( How to use this example )

The following example creates a new Array object weekDayLabels, with elements [Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday] and a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The getDay() method is then called twice, which first shows the day of the month as 6 and then shows the day of the week using weekDayLabels.

var weekDayLabels:Array = new Array("Sunday",
                    "Monday",
                    "Tuesday",
                    "Wednesday",
                    "Thursday",
                    "Friday",
                    "Saturday");

var someBirthday:Date = new Date(1974, 10, 30, 1, 20);
trace(someBirthday);                       // Sat Nov 30 01:20:00 GMT-0800 1974
trace(someBirthday.getDay());            // 6
trace(weekDayLabels[someBirthday.getDay()]); // Saturday

getFullYear

()method 
AS3 function getFullYear():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the full year (a four-digit number, such as 2000) of a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.

Returns
Number — The full year a Date object represents.

Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The getFullYear() method is then called, which retrieves the four-digit year.

var someBirthday:Date = new Date(1974, 10, 30, 1, 20);
trace(someBirthday);           // Sat Nov 30 01:20:00 GMT-0800 1974
trace(someBirthday.getFullYear()); // 1974

getHours

()method 
AS3 function getHours():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the hour (an integer from 0 to 23) of the day portion of a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.

Returns
Number — The hour (0 - 23) of the day a Date object represents.

Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The getHours() and getMinutes() methods are then called, which retrieves the hours and the minutes in 24-hour format. Finally, a string localTime is created and assigned to the result of a call to the function getUSClockTime(), which, in turn calls getHours() and getMinutes() again, resulting in the time 03:05 PM.

var someBirthday:Date = new Date(1974, 10, 30, 15, 5);

trace(someBirthday); // Sat Nov 30 15:20:00 GMT-0800 1974
trace(someBirthday.getHours() + ":" + someBirthday.getMinutes()); // 15:5

var localTime:String = getUSClockTime(someBirthday.getHours(), someBirthday.getMinutes());
trace(localTime);    // 03:05 PM

function getUSClockTime(hrs:uint, mins:uint):String {
    var modifier:String = "PM";
    var minLabel:String = doubleDigitFormat(mins);

    if(hrs > 12) {
        hrs = hrs-12;
    } else if(hrs == 0) {
        modifier = "AM";
        hrs = 12;
    } else if(hrs < 12) {
        modifier = "AM";
    }

    return (doubleDigitFormat(hrs) + ":" + minLabel + " " + modifier);
}

function doubleDigitFormat(num:uint):String {
    if(num < 10) {
        return ("0" + num);
    }
    return num;
}

getMilliseconds

()method 
AS3 function getMilliseconds():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the milliseconds (an integer from 0 to 999) portion of a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.

Returns
Number — The milliseconds portion of a Date object.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The getMilliseconds() method is then called, which retrieves the milliseconds of the Date object now at the time it was created.

var now:Date = new Date();
trace(now.getMilliseconds());

getMinutes

()method 
AS3 function getMinutes():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the minutes (an integer from 0 to 59) portion of a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.

Returns
Number — The minutes portion of a Date object.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The getMinutes() method is then called, which retrieves the minutes of the Date object now at the time it was created.

var now:Date = new Date();
trace(now);
trace(now.getMinutes());

getMonth

()method 
AS3 function getMonth():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the month (0 for January, 1 for February, and so on) portion of this Date according to local time. Local time is determined by the operating system on which the Flash runtimes are running.

Returns
Number — The month (0 - 11) portion of a Date object.

Example  ( How to use this example )

The following example creates a new Array object monthLabels, with elements January through December and a new Date object now with no parameters. The getMonth() method is then called twice, which first returns the month number and then the month name of the month the Date object now was created.

var monthLabels:Array = new Array("January",
                  "February",
                  "March",
                  "April",
                  "May",
                  "June",
                  "July",
                  "August",
                  "September",
                  "October",
                  "November",
                  "December");

var now:Date = new Date();
trace(now.getMonth());
trace(monthLabels[now.getMonth()]);

getSeconds

()method 
AS3 function getSeconds():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the seconds (an integer from 0 to 59) portion of a Date object according to local time. Local time is determined by the operating system on which the Flash runtimes are running.

Returns
Number — The seconds (0 to 59) portion of a Date object.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The getSeconds() method is then called, which retrieves the seconds of the Date object now at the time it was created.

var now:Date = new Date();
trace(now.getSeconds());

getTime

()method 
AS3 function getTime():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the number of milliseconds since midnight January 1, 1970, universal time, for a Date object. Use this method to represent a specific instant in time when comparing two or more Date objects.

Returns
Number — The number of milliseconds since Jan 1, 1970 that a Date object represents.

Example  ( How to use this example )

The following example creates a new Date object mlk with parameters year (1929), month (0 = January), and day (15). The getTime() method is then called, which retrieves the milliseconds since midnight January 1, 1970, which is negative since the year is set to 1929.

var mlk:Date = new Date(1929, 0, 15);
trace(mlk);           // Tue Jan 15 00:00:00 GMT-0800 1929
trace(mlk.getTime()); // -1292601600000

The following example creates a new Date object now with no parameters and then uses the following DateMath (created below) class methods to add time to the original Date object now from the time it was created:
  • addSeconds(): adds 30 seconds to now.
  • addMinutes(): adds 30 minutes to now.
  • addHours(): adds 6 hours to the Date object now.
  • addDays(): adds 30 days to the Date object now.
  • addWeeks(): adds 4 weeks to now.

var now:Date = new Date();
trace(now);
trace(DateMath.addSeconds(now, 30));
trace(DateMath.addMinutes(now, 30));
trace(DateMath.addHours(now, 6));
trace(DateMath.addDays(now, 30));
trace(DateMath.addWeeks(now, 4));

class DateMath {
    public static function addWeeks(date:Date, weeks:Number):Date {
        return addDays(date, weeks*7);
    }

    public static function addDays(date:Date, days:Number):Date {
        return addHours(date, days*24);
    }

    public static function addHours(date:Date, hrs:Number):Date {
        return addMinutes(date, hrs*60);
    }

    public static function addMinutes(date:Date, mins:Number):Date {
        return addSeconds(date, mins*60);
    }

    public static function addSeconds(date:Date, secs:Number):Date {
        var mSecs:Number = secs * 1000;
        var sum:Number = mSecs + date.getTime();
        return new Date(sum);
    }
}
Note: it's important to use getTime when performing Date arithmetic because it will continue to work during leap years and doesn't require a bunch of if logic like following pseudo-code:
 function addMonths(num:Number):void {
     currentMonth = currentMonth + num;
     if(currentMonth > 12) {
         currentYear++;
         currentMonth = currentMonth - 12;
     }
 }
 

getTimezoneOffset

()method 
AS3 function getTimezoneOffset():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the difference, in minutes, between universal time (UTC) and the computer's local time.

Returns
Number — The minutes you need to add to the computer's local time value to equal UTC. If your computer's time is set later than UTC, the return value will be negative.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The getTimezoneOffset() method is then called, which retrieves the difference (in minutes) of the time now was created and Universal Time. The time zone offset is then converted to hours by dividing the result by 60.

var date:Date = new Date();
trace(date.getTimezoneOffset() / 60);

getUTCDate

()method 
AS3 function getUTCDate():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the day of the month (an integer from 1 to 31) of a Date object, according to universal time (UTC).

Returns
Number — The UTC day of the month (1 to 31) that a Date object represents.

See also


Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The getUTCDate() method is then called, which retrieves the day of the month, according to the UTC.

var someBirthday:Date = new Date(1974, 10, 30, 1, 20);
trace(someBirthday);             // Sat Nov 30 01:20:00 GMT-0800 1974
trace(someBirthday.getUTCDate()); // 30

getUTCDay

()method 
AS3 function getUTCDay():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the day of the week (0 for Sunday, 1 for Monday, and so on) of this Date according to universal time (UTC).

Returns
Number — The UTC day of the week (0 to 6) that a Date object represents.

See also


Example  ( How to use this example )

The following example creates a new Array object weekDayLabels, with elements [Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday] and a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The getUTCDay() method is then called twice, which first shows the day of the month as 6 and then shows the day of the week using weekDayLabels, according to the UTC.

var weekDayLabels:Array = new Array("Sunday",
                    "Monday",
                    "Tuesday",
                    "Wednesday",
                    "Thursday",
                    "Friday",
                    "Saturday");

var someBirthday:Date = new Date(1974, 10, 30, 1, 20);
trace(someBirthday);           // Sat Nov 30 01:20:00 GMT-0800 1974
trace(someBirthday.getUTCDay()); // 6
trace(weekDayLabels[someBirthday.getUTCDay()]); // Saturday

getUTCFullYear

()method 
AS3 function getUTCFullYear():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the four-digit year of a Date object according to universal time (UTC).

Returns
Number — The UTC four-digit year a Date object represents.

See also


Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The getUTCFullYear() method is then called, which retrieves the four-digit year, according to the UTC.

var someBirthday:Date = new Date(1974, 10, 30, 1, 20);
trace(someBirthday);                 // Sat Nov 30 01:20:00 GMT-0800 1974
trace(someBirthday.getUTCFullYear()); // 1974

getUTCHours

()method 
AS3 function getUTCHours():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the hour (an integer from 0 to 23) of the day of a Date object according to universal time (UTC).

Returns
Number — The UTC hour of the day (0 to 23) a Date object represents.

See also


Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The getHours() and getMinutes() methods are then called, which retrieves the hours and the minutes in 24-hour format. Finally, a string localTime is created and assigned to the result of a call to the function getUSClockTime(), which, in turn calls getHours() and getMinutes() again, resulting in the time 03:05 PM. Lastly, a String variable utcTime is created in the same manner as localTime, and in this case, the result is the same.

var someBirthday:Date = new Date(1974, 10, 30, 15, 5);

trace(someBirthday); // Sat Nov 30 15:20:00 GMT-0800 1974
trace(someBirthday.getHours() + ":" + someBirthday.getMinutes()); // 15:5

var localTime:String = getUSClockTime(someBirthday.getHours(), someBirthday.getMinutes());
trace(localTime);    // 03:05 PM

var utcTime:String = getUSClockTime(someBirthday.getUTCHours(), someBirthday.getUTCMinutes());
trace(utcTime);      // 11:05 PM

function getUSClockTime(hrs:uint, mins:uint):String {
    var modifier:String = "PM";
    var minLabel:String = doubleDigitFormat(mins);

    if(hrs > 12) {
        hrs = hrs-12;
    } else if(hrs == 0) {
        modifier = "AM";
        hrs = 12;
    } else if(hrs < 12) {
        modifier = "AM";
    }

    return (doubleDigitFormat(hrs) + ":" + minLabel + " " + modifier);
}

function doubleDigitFormat(num:uint):String {
    if(num < 10) {
        return ("0" + num);
    }
    return num;
}

getUTCMilliseconds

()method 
AS3 function getUTCMilliseconds():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the milliseconds (an integer from 0 to 999) portion of a Date object according to universal time (UTC).

Returns
Number — The UTC milliseconds portion of a Date object.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The getUTCMilliseconds() method is then called, which retrieves the milliseconds of the Date object now at the time it was created, according to the UTC

var now:Date = new Date();
trace(now.getUTCMilliseconds());

getUTCMinutes

()method 
AS3 function getUTCMinutes():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the minutes (an integer from 0 to 59) portion of a Date object according to universal time (UTC).

Returns
Number — The UTC minutes portion of a Date object.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The getUTCMinutes() method is then called, which retrieves the minutes of the Date object now at the time it was created, according to the UTC

var now:Date = new Date();
trace(now.getUTCMinutes());

getUTCMonth

()method 
AS3 function getUTCMonth():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the month (0 [January] to 11 [December]) portion of a Date object according to universal time (UTC).

Returns
Number — The UTC month portion of a Date object.

See also


Example  ( How to use this example )

The following example creates a new Array object monthLabels, with elements January through December and a new Date object now with no parameters. The getUTCMonth() method is then called twice, which first returns the month number and then the month name of the month the Date object now was created, according to the UTC

var monthLabels:Array = new Array("January",
                  "February",
                  "March",
                  "April",
                  "May",
                  "June",
                  "July",
                  "August",
                  "September",
                  "October",
                  "November",
                  "December");

var now:Date = new Date();
trace(now.getMonth());
trace(now.getUTCMonth());
trace(monthLabels[now.getUTCMonth()]);

getUTCSeconds

()method 
AS3 function getUTCSeconds():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the seconds (an integer from 0 to 59) portion of a Date object according to universal time (UTC).

Returns
Number — The UTC seconds portion of a Date object.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The getUTCSeconds() method is then called, which retrieves the seconds of the Date object now at the time it was created, according to the UTC

var now:Date = new Date();
trace(now.getUTCSeconds());

parse

()method 
public static function parse(date:String):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Converts a string representing a date into a number equaling the number of milliseconds elapsed since January 1, 1970, UTC.

Parameters

date:String — A string representation of a date, which conforms to the format for the output of Date.toString(). The date format for the output of Date.toString() is:
     Day Mon DD HH:MM:SS TZD YYYY
     

For example:

     Wed Apr 12 15:30:17 GMT-0700 2006
     

The Time Zone Designation (TZD) is always in the form GMT-HHMM or UTC-HHMM indicating the hour and minute offset relative to Greenwich Mean Time (GMT), which is now also called universal time (UTC). The year month and day terms can be separated by a forward slash (/) or by spaces, but never by a dash (-). Other supported formats include the following (you can include partial representations of these formats; that is, just the month, day, and year):

     MM/DD/YYYY HH:MM:SS TZD
     HH:MM:SS TZD Day Mon/DD/YYYY 
     Mon DD YYYY HH:MM:SS TZD
     Day Mon DD HH:MM:SS TZD YYYY
     Day DD Mon HH:MM:SS TZD YYYY
     Mon/DD/YYYY HH:MM:SS TZD
     YYYY/MM/DD HH:MM:SS TZD
     

Returns
Number — A number representing the milliseconds elapsed since January 1, 1970, UTC.

See also


Example  ( How to use this example )

The following example assigns a date string to dateParsed for November 30, 1974. The Date.parse() method is then called, which converts the date into milliseconds since January 1, 1970.
var dateParsed:String = "Sat Nov 30 1974";

var milliseconds:Number = Date.parse(dateParsed);
trace(milliseconds); // 155030400000

setDate

()method 
AS3 function setDate(day:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the day of the month, according to local time, and returns the new time in milliseconds. Local time is determined by the operating system on which the Flash runtimes are running.

Parameters

day:Number — An integer from 1 to 31.

Returns
Number — The new time, in milliseconds.

Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The method getDate() is then called, which retrieves the day of the month. Next setDate() is called with the day parameter set to 20 and then getDate() is called again, which retrieves the newly set day of month.

var someBirthday:Date = new Date(1974, 10, 30, 1, 20);
trace(someBirthday);            // Sat Nov 30 01:20:00 GMT-0800 1974
trace(someBirthday.getDate()); // 30

someBirthday.setDate(20);
trace(someBirthday.getDate()); // 20

setFullYear

()method 
AS3 function setFullYear(year:Number, month:Number, day:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the year, according to local time, and returns the new time in milliseconds. If the month and day parameters are specified, they are set to local time. Local time is determined by the operating system on which the Flash runtimes are running.

Calling this method does not modify the other fields of the Date but Date.getUTCDay() and Date.getDay() can report a new value if the day of the week changes as a result of calling this method.

Parameters

year:Number — A four-digit number specifying a year. Two-digit numbers do not represent four-digit years; for example, 99 is not the year 1999, but the year 99.
 
month:Number — An integer from 0 (January) to 11 (December).
 
day:Number — A number from 1 to 31.

Returns
Number — The new time, in milliseconds.

See also


Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The method getFullYear() is then called, which retrieves the four-digit year. Next setFullYear() is called with the year parameter set to 2000 and then getFullYear() is called again, which retrieves the newly set year.

var someBirthday:Date = new Date(1974, 10, 30, 1, 20);
trace(someBirthday);           // Sat Nov 30 01:20:00 GMT-0800 1974
trace(someBirthday.getFullYear()); // 1974

someBirthday.setFullYear(2000);
trace(someBirthday.getFullYear()); // 2000

setHours

()method 
AS3 function setHours(hour:Number, minute:Number, second:Number, millisecond:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the hour, according to local time, and returns the new time in milliseconds. Local time is determined by the operating system on which the Flash runtimes are running.

Parameters

hour:Number — An integer from 0 (midnight) to 23 (11 p.m.).
 
minute:Number — An integer from 0 to 59.
 
second:Number — An integer from 0 to 59.
 
millisecond:Number — An integer from 0 to 999.

Returns
Number — The new time, in milliseconds.

Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The methods getHours() and getMinutes() are then called, which retrieves the hours and minutes. Next setHours() is called with the hour parameter set to 12 and then getHours() and getMinutes() are called again, which retrieves the newly set hours and minutes.

var someBirthday:Date = new Date(1974, 10, 30, 15, 20);

trace(someBirthday); // Sat Nov 30 15:20:00 GMT-0800 1974
trace(someBirthday.getHours() + ":" + someBirthday.getMinutes()); // 15:20

someBirthday.setHours(12);
trace(someBirthday.getHours() + ":" + someBirthday.getMinutes()); // 12:20

setMilliseconds

()method 
AS3 function setMilliseconds(millisecond:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the milliseconds, according to local time, and returns the new time in milliseconds. Local time is determined by the operating system on which the Flash runtimes are running.

Parameters

millisecond:Number — An integer from 0 to 999.

Returns
Number — The new time, in milliseconds.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The method getMilliseconds() is then called, which retrieves the milliseconds when now was created. Then another new Date object before with an additional call to setMilliseconds() with the millisecond parameter set to 4 and getMilliseconds() is called again, which retrieves the newly set milliseconds.

var now:Date = new Date();
trace(now);
trace(now.getMilliseconds());

var before:Date = new Date(now.setMilliseconds(4));
trace(before);
trace(before.getMilliseconds());

setMinutes

()method 
AS3 function setMinutes(minute:Number, second:Number, millisecond:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the minutes, according to local time, and returns the new time in milliseconds. Local time is determined by the operating system on which the Flash runtimes are running.

Parameters

minute:Number — An integer from 0 to 59.
 
second:Number — An integer from 0 to 59.
 
millisecond:Number — An integer from 0 to 999.

Returns
Number — The new time, in milliseconds.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The method getMinutes() is then called, which retrieves the minutes when now was created. Then another new Date object before with an additional call to setMinutes() with the minute parameter set to 0 and getMinutes() is called again, which retrieves the newly set minutes.

var now:Date = new Date();
trace(now);
trace(now.getMinutes());

var before:Date = new Date(now.setMinutes(0));
trace(before);
trace(before.getMinutes());

setMonth

()method 
AS3 function setMonth(month:Number, day:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the month and optionally the day of the month, according to local time, and returns the new time in milliseconds. Local time is determined by the operating system on which the Flash runtimes are running.

Parameters

month:Number — An integer from 0 (January) to 11 (December).
 
day:Number — An integer from 1 to 31.

Returns
Number — The new time, in milliseconds.

Example  ( How to use this example )

The following example creates a new Array object monthLabels, with elements January through December and a new month object now with no parameters. The method getMonth() is then called, which retrieves the month in which now was created. Next setMonth() is called with the month parameter set to 0 and then getMonth() is called again, which retrieves the newly set month..

var monthLabels:Array = new Array("January",
                  "February",
                  "March",
                  "April",
                  "May",
                  "June",
                  "July",
                  "August",
                  "September",
                  "October",
                  "November",
                  "December");

var now:Date = new Date();
trace(now.getMonth());
trace(monthLabels[now.getMonth()]);

now.setMonth(0);
trace(now.getMonth());             // 0
trace(monthLabels[now.getMonth()]); // January

setSeconds

()method 
AS3 function setSeconds(second:Number, millisecond:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the seconds, according to local time, and returns the new time in milliseconds. Local time is determined by the operating system on which the Flash runtimes are running.

Parameters

second:Number — An integer from 0 to 59.
 
millisecond:Number — An integer from 0 to 999.

Returns
Number — The new time, in milliseconds.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The method getseconds() is then called, which retrieves the seconds when now was created. Then the setSeconds() is called with the second parameter set to 0 and getSeconds() is called again, which retrieves the newly set seconds.

var now:Date = new Date();
trace(now.getSeconds());

now.setSeconds(0);
trace(now.getSeconds()); // 0

setTime

()method 
AS3 function setTime(millisecond:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the date in milliseconds since midnight on January 1, 1970, and returns the new time in milliseconds.

Parameters

millisecond:Number — An integer value where 0 is midnight on January 1, universal time (UTC).

Returns
Number — The new time, in milliseconds.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The setTime() method is then called, with the millisecond parameter set to -1292601600000, which sets the time to Tue Jan 15 00:00:00 GMT-0800 1929.

var now:Date = new Date();
trace(now);

now.setTime(-1292601600000);
trace(now); // Tue Jan 15 00:00:00 GMT-0800 1929

setUTCDate

()method 
AS3 function setUTCDate(day:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the day of the month, in universal time (UTC), and returns the new time in milliseconds. Calling this method does not modify the other fields of a Date object, but the Date.getUTCDay() and Date.getDay() methods can report a new value if the day of the week changes as a result of calling this method.

Parameters

day:Number — A number; an integer from 1 to 31.

Returns
Number — The new time, in milliseconds.

See also


Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The method getUTCDate() is called and correctly returns the day of the month. Next setUTCDate() is called with the day parameter set to 1 and a trace() statement confirms the date was correctly set.

var someBirthday:Date = new Date(1974, 10, 30, 1, 20);
trace(someBirthday); // Sat Nov 30 01:20:00 GMT-0800 1974
trace(someBirthday.getUTCDate()); // 30

someBirthday.setUTCDate(1);
trace(someBirthday); // Fri Nov 1 01:20:00 GMT-0800 1974

setUTCFullYear

()method 
AS3 function setUTCFullYear(year:Number, month:Number, day:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the year, in universal time (UTC), and returns the new time in milliseconds.

Optionally, this method can also set the month and day of the month. Calling this method does not modify the other fields, but the Date.getUTCDay() and Date.getDay() methods can report a new value if the day of the week changes as a result of calling this method.

Parameters

year:Number — An integer that represents the year specified as a full four-digit year, such as 2000.
 
month:Number — An integer from 0 (January) to 11 (December).
 
day:Number — An integer from 1 to 31.

Returns
Number — An integer.

See also


Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The method getUTCFullYear() is called and correctly returns the four-digit year. Next setUTCFullYear() is called with the year parameter set to 1975 and a trace() statement confirms the year was correctly set.

var someBirthday:Date = new Date(1974, 10, 30, 1, 20);
trace(someBirthday); // Sat Nov 30 01:20:00 GMT-0800 1974
trace(someBirthday.getUTCFullYear()); // 1974

someBirthday.setUTCFullYear(1975);
trace(someBirthday); // Thu Nov 30 01:20:00 GMT-0800 1975

setUTCHours

()method 
AS3 function setUTCHours(hour:Number, minute:Number, second:Number, millisecond:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the hour, in universal time (UTC), and returns the new time in milliseconds. Optionally, the minutes, seconds, and milliseconds can be specified.

Parameters

hour:Number — An integer from 0 (midnight) to 23 (11 p.m.).
 
minute:Number — An integer from 0 to 59.
 
second:Number — An integer from 0 to 59.
 
millisecond:Number — An integer from 0 to 999.

Returns
Number — The new time, in milliseconds.

Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20). The methods getHours(), getMinutes(), getUTCHours(), and getUTCMinutes() are then called, which retrieves the hours and minutes. Next setUTCHours() is called with the hour parameter set to 12 and then the methods getHours(), getMinutes(), getUTCHours(), and getUTCMinutes() are re-called and correctly display the updated hour.

var someBirthday:Date = new Date(1974, 10, 30, 15, 20);

trace(someBirthday); // Sat Nov 30 15:20:00 GMT-0800 1974
trace(someBirthday.getHours() + ":" + someBirthday.getMinutes());     // 15:20
trace(someBirthday.getUTCHours() + ":" + someBirthday.getUTCMinutes()); // 23:20

someBirthday.setUTCHours(12);
trace(someBirthday.getHours() + ":" + someBirthday.getMinutes());     // 4:20
trace(someBirthday.getUTCHours() + ":" + someBirthday.getUTCMinutes()); // 12:20

setUTCMilliseconds

()method 
AS3 function setUTCMilliseconds(millisecond:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the milliseconds, in universal time (UTC), and returns the new time in milliseconds.

Parameters

millisecond:Number — An integer from 0 to 999.

Returns
Number — The new time, in milliseconds.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The method getUTCMilliseconds() is then called, which retrieves the UTCMilliseconds when now was created. Then another new Date object before with an additional call to setUTCMilliseconds() with the millisecond parameter set to 4 and getUTCMilliseconds() is called again, which retrieves the newly set milliseconds.


var now:Date = new Date();
trace(now);
trace(now.getUTCMilliseconds());

var before:Date = new Date(now.setUTCMilliseconds(4));
trace(before);
trace(before.getUTCMilliseconds());

setUTCMinutes

()method 
AS3 function setUTCMinutes(minute:Number, second:Number, millisecond:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the minutes, in universal time (UTC), and returns the new time in milliseconds. Optionally, you can specify the seconds and milliseconds.

Parameters

minute:Number — An integer from 0 to 59.
 
second:Number — An integer from 0 to 59.
 
millisecond:Number — An integer from 0 to 999.

Returns
Number — The new time, in milliseconds.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The method getUTCMinutes() is then called, which retrieves the UTCMinutes when now was created. Then another new Date object before with an additional call to setUTCMinutes() with the minute parameter set to 0 and getUTCMinutes() is called again, which retrieves the newly set minutes.

var now:Date = new Date();
trace(now);
trace(now.getUTCMinutes());

var before:Date = new Date(now.setUTCMinutes(0));
trace(before);
trace(before.getUTCMinutes());

setUTCMonth

()method 
AS3 function setUTCMonth(month:Number, day:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the month, and optionally the day, in universal time(UTC) and returns the new time in milliseconds. Calling this method does not modify the other fields, but the Date.getUTCDay() and Date.getDay() methods might report a new value if the day of the week changes as a result of calling this method.

Parameters

month:Number — An integer from 0 (January) to 11 (December).
 
day:Number — An integer from 1 to 31.

Returns
Number — The new time, in milliseconds.

See also


Example  ( How to use this example )

The following example creates a new Array object UTCMonthLabels, with elements January through December and a new UTCMonth object now with no parameters. The method getUTCMonth() is then called, which retrieves the UTCMonth in which now was created. Next setUTCMonth() is called with the month parameter set to 0 and then getUTCMonth() is called again, which retrieves the newly set month..

var UTCMonthLabels:Array = new Array("January",
                  "February",
                  "March",
                  "April",
                  "May",
                  "June",
                  "July",
                  "August",
                  "September",
                  "October",
                  "November",
                  "December");

var now:Date = new Date();
trace(now.getUTCMonth());
trace(UTCMonthLabels[now.getUTCMonth()]);

now.setUTCUTCMonth(0);
trace(now.getUTCMonth());              // 0
trace(UTCMonthLabels[now.getUTCMonth()]); // January

setUTCSeconds

()method 
AS3 function setUTCSeconds(second:Number, millisecond:Number):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Sets the seconds, and optionally the milliseconds, in universal time (UTC) and returns the new time in milliseconds.

Parameters

second:Number — An integer from 0 to 59.
 
millisecond:Number — An integer from 0 to 999.

Returns
Number — The new time, in milliseconds.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters. The method getUTCSeconds() is then called, which retrieves the seconds when now was created. Then the setUTCSeconds() is called with the second parameter set to 0 and getUTCSeconds() is called again, which retrieves the newly set seconds.

var now:Date = new Date();
trace(now.getUTCSeconds());

now.setUTCSeconds(0);
trace(now.getUTCSeconds()); // 0

toDateString

()method 
AS3 function toDateString():String

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns a string representation of the day and date only, and does not include the time or timezone. Contrast with the following methods:

  • Date.toTimeString(), which returns only the time and timezone
  • Date.toString(), which returns not only the day and date, but also the time and timezone.

Returns
String — The string representation of day and date only.

See also


Example  ( How to use this example )

The following example creates a new Date object now with no parameters and then the following methods are called within a trace() statement
  • toString: displays all parameters for now at the time now was created.
  • toDateString(): displays the day, month, and year parameters for the time now was created.

var now:Date = new Date();
trace(now);
trace(now.toDateString());

toLocaleDateString

()method 
AS3 function toLocaleDateString():String

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns a String representation of the day and date only, and does not include the time or timezone. This method returns the same value as Date.toDateString. Contrast with the following methods:

  • Date.toTimeString(), which returns only the time and timezone
  • Date.toString(), which returns not only the day and date, but also the time and timezone.

Returns
String — The String representation of day and date only.

See also

toLocaleString

()method 
AS3 function toLocaleString():String

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns a String representation of the day, date, time, given in local time. Contrast with the Date.toString() method, which returns the same information (plus the timezone) with the year listed at the end of the string.

Returns
String — A string representation of a Date object in the local timezone.

toLocaleTimeString

()method 
AS3 function toLocaleTimeString():String

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns a String representation of the time only, and does not include the day, date, year, or timezone. Contrast with the Date.toTimeString() method, which returns the time and timezone.

Returns
String — The string representation of time and timezone only.

See also

toString

()method 
AS3 function toString():String

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns a String representation of the day, date, time, and timezone. The date format for the output is:

     Day Mon Date HH:MM:SS TZD YYYY
     

For example:

     Wed Apr 12 15:30:17 GMT-0700 2006
     

Returns
String — The string representation of a Date object.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters and then toString is called within a trace() statement, which displays all parameters for now at the time now was created.


var now:Date = new Date();
trace(now);

toTimeString

()method 
AS3 function toTimeString():String

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns a String representation of the time and timezone only, and does not include the day and date. Contrast with the Date.toDateString() method, which returns only the day and date.

Returns
String — The string representation of time and timezone only.

See also

toUTCString

()method 
AS3 function toUTCString():String

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns a String representation of the day, date, and time in universal time (UTC). For example, the date February 1, 2005 is returned as Tue Feb 1 00:00:00 2005 UTC.

Returns
String — The string representation of a Date object in UTC time.

See also

UTC

()method 
public static function UTC(year:Number, month:Number, date:Number = 1, hour:Number = 0, minute:Number = 0, second:Number = 0, millisecond:Number = 0):Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the number of milliseconds between midnight on January 1, 1970, universal time, and the time specified in the parameters. This method uses universal time, whereas the Date constructor uses local time.

This method is useful if you want to pass a UTC date to the Date class constructor. Because the Date class constructor accepts the millisecond offset as an argument, you can use the Date.UTC() method to convert your UTC date into the corresponding millisecond offset, and send that offset as an argument to the Date class constructor:

Parameters

year:Number — A four-digit integer that represents the year (for example, 2000).
 
month:Number — An integer from 0 (January) to 11 (December).
 
date:Number (default = 1) — An integer from 1 to 31.
 
hour:Number (default = 0) — An integer from 0 (midnight) to 23 (11 p.m.).
 
minute:Number (default = 0) — An integer from 0 to 59.
 
second:Number (default = 0) — An integer from 0 to 59.
 
millisecond:Number (default = 0) — An integer from 0 to 999.

Returns
Number — The number of milliseconds since January 1, 1970 and the specified date and time.

Example  ( How to use this example )

The following example creates a new Date object someBirthday with parameters year (1974), month (10 = November), day (30), hour (1) and minute (20) using local time. Then a call to UTC() within a setTime() method resets the same parameters to universal time.

var someBirthday:Date = new Date(1974, 10, 30, 15, 20);
trace(someBirthday.toString());

someBirthday.setTime(Date.UTC(1974, 10, 30, 15, 20));
trace(someBirthday.toString());

valueOf

()method 
AS3 function valueOf():Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0, Flash Lite 4

Returns the number of milliseconds since midnight January 1, 1970, universal time, for a Date object.

Returns
Number — The number of milliseconds since January 1, 1970 that a Date object represents.

Example  ( How to use this example )

The following example creates a new Date object now with no parameters The getTime() method is then called, which retrieves the number of milliseconds between the time now was created and midnight on January 1, 1970, and then valueOf() is called, which retrieves the same thing.


var now:Date = new Date();
trace(now.getTime());
trace(now.valueOf());
DateExample.as

The following example shows various uses of the Date() constructor to assign the following variables:
  • myDate1 calls Date() with no parameters, which sets myDate1 to the current date and time (according to your current system's date and time).
  • myDate2 calls Date() with the year (2000), month (0 = January), and day (1) parameters passed to it.
  • myDate3 calls Date() with the year (65 = 1965), month (2 = March), the day (6), the hour (9), the minute (30), the second (15) and the millisecond-+ (0) passed as parameters.
  • myDate4 calls Date() with the time value representing the number of milliseconds before (since the value is negative) 0:00:00 GMT January 1, 1970.

package {
    import flash.display.Sprite;
    
    public class DateExample extends Sprite{
        public function DateExample() {
            var myDate1:Date = new Date();
            trace(myDate1); // [NOW]

            var myDate2:Date = new Date(2000, 0, 1);
            trace(myDate2); // Sat Jan 1 00:00:00 GMT-0800 2000

            var myDate3:Date = new Date(65, 2, 6, 9, 30, 15, 0);
            trace(myDate3); // Sat Mar 6 09:30:15 GMT-0800 1965

            var myDate4:Date = new Date(-14159025000);
            trace(myDate4); // Sun Jul 20 19:56:15 GMT-0700 1969
        }        
    }    
}