| Package | Top Level |
| Class | public final dynamic class Date |
| Inheritance | Date Object |
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 Flash Player version. Flash Player 6 and later versions handle daylight saving time on the following operating systems in these ways:
Flash Player 5 handles daylight saving time on the following operating systems as follows:
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(), Date.toLocaleDateString().
To compute relative time or time elapsed, see the getTimer() method in the flash.utils package.
| flash.utils.getTimer() |
| Property | Defined by | ||
|---|---|---|---|
![]() | constructor : 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 | ||
![]() | prototype : 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 the computer's local time and universal
time (UTC).
| Date | ||
| Function | Defined 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 the computer's local time and universal
time (UTC).
| 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 | ||
![]() |
Indicates whether an object has a specified property defined.
| Object | |
![]() |
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 | ||
![]() |
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 | ||
|
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 | ||
|
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 | ||
![]() |
Sets the availability of a dynamic property for loop operations.
| Object | |
|
Sets the seconds, according to local time, and returns the new time in milliseconds.
| Date | ||
|
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 | ||
|
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 | ||
|
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 | ||
|
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 | ||
date:Number [read-write]Date object
according to local time. Local time is determined by the operating system on which
Flash Player is running.
public function get date():Number
public function set date(value:Number):void
| getDate(), setDate() |
dateUTC:Number [read-write]Date object
according to universal time (UTC).
public function get dateUTC():Number
public function set dateUTC(value:Number):void
| getUTCDate(), setUTCDate() |
day:Number [read-only]Date according to local time. Local time is determined by the operating
system on which Flash Player is running.
public function get day():Number
| getDay() |
dayUTC:Number [read-only]Date
according to universal time (UTC).
public function get dayUTC():Number
| getUTCDay() |
fullYear:Number [read-write]Date object
according to local time. Local time is determined by the operating system on which
Flash Player is running.
public function get fullYear():Number
public function set fullYear(value:Number):void
| getFullYear(), setFullYear() |
fullYearUTC:Number [read-write]Date object according to universal time (UTC).
public function get fullYearUTC():Number
public function set fullYearUTC(value:Number):void
| getUTCFullYear(), setUTCFullYear() |
hours:Number [read-write]Date object
according to local time. Local time is determined by the operating system on which
Flash Player is running.
public function get hours():Number
public function set hours(value:Number):void
| getHours(), setHours() |
hoursUTC:Number [read-write]Date object
according to universal time (UTC).
public function get hoursUTC():Number
public function set hoursUTC(value:Number):void
| getUTCHours(), setUTCHours() |
milliseconds:Number [read-write]Date object
according to local time. Local time is determined by the operating system on which
Flash Player is running.
public function get milliseconds():Number
public function set milliseconds(value:Number):void
| getMilliseconds(), setMilliseconds() |
millisecondsUTC:Number [read-write]Date object
according to universal time (UTC).
public function get millisecondsUTC():Number
public function set millisecondsUTC(value:Number):void
| getUTCMilliseconds(), setUTCMilliseconds() |
minutes:Number [read-write]Date object
according to local time. Local time is determined by the operating system on which
Flash Player is running.
public function get minutes():Number
public function set minutes(value:Number):void
| getMinutes(), setMinutes() |
minutesUTC:Number [read-write]Date object
according to universal time (UTC).
public function get minutesUTC():Number
public function set minutesUTC(value:Number):void
| getUTCMinutes(), setUTCMinutes() |
month:Number [read-write]
Date object according to local time. Local time is determined by the operating system
on which Flash Player is running.
public function get month():Number
public function set month(value:Number):void
| getMonth(), setMonth() |
monthUTC:Number [read-write]Date object
according to universal time (UTC).
public function get monthUTC():Number
public function set monthUTC(value:Number):void
| getUTCMonth(), setUTCMonth() |
seconds:Number [read-write]Date object
according to local time. Local time is determined by the operating system on which
Flash Player is running.
public function get seconds():Number
public function set seconds(value:Number):void
| getSeconds(), setSeconds() |
secondsUTC:Number [read-write]Date object
according to universal time (UTC).
public function get secondsUTC():Number
public function set secondsUTC(value:Number):void
| getUTCSeconds(), setUTCSeconds() |
time:Number [read-write]Date object. Use this method to represent a specific instant in time
when comparing two or more Date objects.
public function get time():Number
public function set time(value:Number):void
| getTime(), setTime() |
timezoneOffset:Number [read-only] public function get timezoneOffset():Number
| getTimezoneOffset() |
public function Date(yearOrTimevalue:Object, month:Number, date:Number = 1, hour:Number = 0, minute:Number = 0, second:Number = 0, millisecond:Number = 0)
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 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:
toString())toLocaleString())toDateString())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.
|
| getMonth(), getDate(), getFullYear() |
public function getDate():Number
Date object
according to local time. Local time is determined by the operating system on which
Flash Player is running.
Returns
Number —
The day of the month (1 - 31) a Date object represents.
|
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
}
}
}
| getMonth(), getFullYear() |
public function getDay():Number
Date according to local time. Local time is determined by the operating
system on which Flash Player is running.
Returns
Number —
A numeric version of the day of the week (0 - 6) a Date object
represents.
|
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
public function getFullYear():Number
Date object
according to local time. Local time is determined by the operating system on which
Flash Player is running.
Returns
Number —
The full year a Date object represents.
|
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
public function getHours():Number
Date object
according to local time. Local time is determined by the operating system on which
Flash Player is running.
Returns
Number —
The hour (0 - 23) of the day a Date object represents.
|
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;
}
public function getMilliseconds():Number
Date object
according to local time. Local time is determined by the operating system on which
Flash Player is running.
Returns
Number —
The milliseconds portion of a 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());
public function getMinutes():Number
Date object
according to local time. Local time is determined by the operating system on which
Flash Player is running.
Returns
Number —
The minutes portion of a 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());
public function getMonth():Number
Date according to local time. Local time is determined by the operating system
on which Flash Player is running.
Returns
Number —
The month (0 - 11) portion of a Date 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()]);
public function getSeconds():Number
Date object
according to local time. Local time is determined by the operating system on which
Flash Player is running.
Returns
Number —
The seconds (0 to 59) portion of a 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());
public function getTime():Number
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.
|
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
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 addHours(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);
}
}
function addMonths(num:Number):void {
currentMonth = currentMonth + num;
if(currentMonth > 12) {
currentYear++;
currentMonth = currentMonth - 12;
}
}
public function getTimezoneOffset():Number
Number —
Difference, in minutes, of local time and universal time (UTC).
|
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);
public function getUTCDate():Number
Date object,
according to universal time (UTC).
Returns
Number —
The UTC day of the month (1 to 31) that a Date object represents.
|
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
| getDate() |
public function getUTCDay():Number
Date
according to universal time (UTC).
Returns
Number —
The UTC day of the week (0 to 6) that a Date object represents.
|
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
| getDay() |
public function getUTCFullYear():Number
Date object according to universal time (UTC).
Returns
Number —
The UTC four-digit year a Date object represents.
|
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
| getFullYear() |
public function getUTCHours():Number
Date object
according to universal time (UTC).
Returns
Number —
The UTC hour of the day (0 to 23) a Date object represents.
|
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); // 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;
}
| getHours() |
public function getUTCMilliseconds():Number
Date object
according to universal time (UTC).
Returns
Number —
The UTC milliseconds portion of a 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());
public function getUTCMinutes():Number
Date object
according to universal time (UTC).
Returns
Number —
The UTC minutes portion of a 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());
public function getUTCMonth():Number
Date object
according to universal time (UTC).
Returns
Number —
The UTC month portion of a Date 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()]);
| getMonth() |
public function getUTCSeconds():Number
Date object
according to universal time (UTC).
Returns
Number —
The UTC seconds portion of a 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());
public static function parse(date:String):Number
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 Date HH:MM:SS TZD YYYY
For example:
Wed Apr 12 15:30:17 GMT-0700 2006
Other supported formats include (and you can include partial representations of these, meaning just the month, day, and year):
MM/DD/YYYY HH:MM:SS TZD
YYYY-MM-DDThh:mm:ssTZD
|
Number —
A number representing the milliseconds elapsed since January 1, 1970, UTC.
|
dateParsed for November 30th, 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); // output 155030400000
| Date.toString() |
public function setDate(day:Number):Number
day:Number — An integer from 1 to 31.
|
Number —
The new time, in milliseconds.
|
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
public function setFullYear(year:Number, month:Number, day:Number):Number
month and day parameters are specified,
they are set to local time. Local time is determined by the operating system on which
Flash Player is 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.
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.
|
Number —
The new time, in milliseconds.
|
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
| getUTCDay(), getDay() |
public function setHours(hour:Number, minute:Number, second:Number, millisecond:Number):Number
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.
|
Number —
The new time, in milliseconds.
|
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
public function setMilliseconds(millisecond:Number):Number
millisecond:Number — An integer from 0 to 999.
|
Number —
The new time, in milliseconds.
|
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());
public function setMinutes(minute:Number, second:Number, millisecond:Number):Number
minute:Number — An integer from 0 to 59.
|
|
second:Number — An integer from 0 to 59.
|
|
millisecond:Number — An integer from 0 to 999.
|
Number —
The new time, in milliseconds.
|
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());
public function setMonth(month:Number, day:Number):Number
month:Number — An integer from 0 (January) to 11 (December).
|
|
day:Number — An integer from 1 to 31.
|
Number —
The new time, in milliseconds.
|
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
public function setSeconds(second:Number, millisecond:Number):Number
second:Number — An integer from 0 to 59.
|
|
millisecond:Number — An integer from 0 to 999.
|
Number —
The new time, in milliseconds.
|
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
public function setTime(millisecond:Number):Number
millisecond:Number — An integer value where 0 is midnight on January 1, universal time (UTC).
|
Number —
The new time, in milliseconds.
|
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
public function setUTCDate(day:Number):Number
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.
|
Number —
The new time, in milliseconds.
|
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
| getUTCDay(), getDay() |
public function setUTCFullYear(year:Number, month:Number, day:Number):Number
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.
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.
|
Number —
An integer.
|
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
| getUTCDay(), getDay() |
public function setUTCHours(hour:Number, minute:Number, second:Number, millisecond:Number):Number
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.
|
Number —
The new time, in milliseconds.
|
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
public function setUTCMilliseconds(millisecond:Number):Number
millisecond:Number — An integer from 0 to 999.
|
Number —
The new time, in milliseconds.
|
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());
public function setUTCMinutes(minute:Number, second:Number, millisecond:Number):Number
minute:Number — An integer from 0 to 59.
|
|
second:Number — An integer from 0 to 59.
|
|
millisecond:Number — An integer from 0 to 999.
|
Number —
The new time, in milliseconds.
|
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.getUTCUTCMinutes()); var before:Date = new Date(now.setUTCUTCMinutes(0)); trace(before); trace(before.getUTCUTCMinutes());
public function setUTCMonth(month:Number, day:Number):Number
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.
|
Number —
The new time, in milliseconds.
|
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.getUTCUTCMonth());
trace(UTCMonthLabels[now.getUTCUTCMonth()]);
now.setUTCUTCMonth(0);
trace(now.getUTCUTCMonth()); // 0
trace(UTCMonthLabels[now.getUTCUTCMonth()]); // January
| getDay() |
public function setUTCSeconds(second:Number, millisecond:Number):Number
second:Number — An integer from 0 to 59.
|
|
millisecond:Number — An integer from 0 to 999.
|
Number —
The new time, in milliseconds.
|
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
public function toDateString():String
Date.toTimeString(), which returns only the time and timezoneDate.toString(), which returns not only the day and date, but also the time and timezone.String —
The string representation of day and date only.
|
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());
| toString() |
public function toLocaleDateString():String
Date.toDateString.
Contrast with the following methods:
Date.toTimeString(), which returns only the time and timezoneDate.toString(), which returns not only the day and date, but also the
time and timezone.String —
The String representation of day and date only.
|
| toDateString(), toTimeString(), toString() |
public function toLocaleString():String
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.
|
public function toLocaleTimeString():String
Date.toTimeString() method, which returns the time and timezone.
Returns
String —
The string representation of time and timezone only.
|
| toTimeString() |
public function toString():String
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.
|
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);
public function toTimeString():String
Date.toDateString() method, which returns only the day and date.
Returns
String —
The string representation of time and timezone only.
|
| toDateString() |
public function toUTCString():String
Tue Feb 1 00:00:00 2005 UTC.
Returns
String —
The string representation of a Date object in UTC time.
|
| toString() |
public static function UTC(year:Number, month:Number, date:Number = 1, hour:Number = 0, minute:Number = 0, second:Number = 0, millisecond:Number = 0):Number
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:
Parametersyear: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.
|
Number —
The number of milliseconds since January 1, 1970 and the specified date and time.
|
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());
public function valueOf():Number
Date object.
Returns
Number —
The number of milliseconds since January 1, 1970 that a Date object represents.
|
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());
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
}
}
}