Date


Object   |   +-Date public class Date extends Object

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 the operating system on which Flash Player is running. 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() method is an exception; it is a static method.

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:

  • 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 call the methods of the Date class, you must first create a Date object using the constructor for the Date class, described later in this section.

Availability: ActionScript 1.0; Flash Player 5

Property summary

Properties inherited from class Object

constructor (Object.constructor property), __proto__ (Object.__proto__ property), prototype (Object.prototype property), __resolve (Object.__resolve property)


Constructor summary

Signature

Description

Date ([yearOrTimevalue:Number], [month:Number], [date:Number], [hour:Number], [minute:Number], [second:Number], [millisecond:Number])

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


Method summary

Modifiers

Signature

Description

 

getdate() : Number

Returns the day of the month (an integer from 1 to 31) of the specified Date object according to local time.

 

getday() : Number

Returns the day of the week (0 for Sunday, 1 for Monday, and so on) of the specified Date object according to local time.

 

getFullYear() : Number

Returns the full year (a four-digit number, such as 2000) of the specified Date object, according to local time.

 

getHours() : Number

Returns the hour (an integer from 0 to 23) of the specified Date object, according to local time.

 

getMilliseconds() : Number

Returns the milliseconds (an integer from 0 to 999) of the specified Date object, according to local time.

 

getMinutes() : Number

Returns the minutes (an integer from 0 to 59) of the specified Date object, according to local time.

 

getMonth() : Number

Returns the month (0 for January, 1 for February, and so on) of the specified Date object, according to local time.

 

getSeconds() : Number

Returns the seconds (an integer from 0 to 59) of the specified Date object, according to local time.

 

getTime() : Number

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

 

getTimezoneOffset() : Number

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

 

getUTCDate() : Number

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

 

getUTCDay() : Number

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

 

getUTCFullYear() : Number

Returns the four-digit year of the specified Date object, according to universal time.

 

getUTCHours() : Number

Returns the hour (an integer from 0 to 23) of the specified Date object, according to universal time.

 

getUTCMilliseconds() : Number

Returns the milliseconds (an integer from 0 to 999) of the specified Date object, according to universal time.

 

getUTCMinutes() : Number

Returns the minutes (an integer from 0 to 59) of the specified Date object, according to universal time.

 

getUTCMonth() : Number

Returns the month (0 [January] to 11 [December]) of the specified Date object, according to universal time.

 

getUTCSeconds() : Number

Returns the seconds (an integer from 0 to 59) of the specified Date object, according to universal time.

 

getUTCYear() : Number

Returns the year of this Date according to universal time (UTC).

 

getYear() : Number

Returns the year of the specified Date object, according to local time.

 

setDate(date:Number) : Number

Sets the day of the month for the specified Date object, according to local time, and returns the new time in milliseconds.

 

setFullYear(year:Number, [month:Number], [date:Number]) : Number

Sets the year of the specified Date object, according to local time and returns the new time in milliseconds.

 

setHours(hour:Number) : Number

Sets the hours for the specified Date object according to local time and returns the new time in milliseconds.

 

setMilliseconds(millisecond:Number) : Number

Sets the milliseconds for the specified Date object according to local time and returns the new time in milliseconds.

 

setMinutes(minute:Number) : Number

Sets the minutes for a specified Date object according to local time and returns the new time in milliseconds.

 

setMonth(month:Number, [date:Number]) : Number

Sets the month for the specified Date object in local time and returns the new time in milliseconds.

 

setSeconds(second:Number) : Number

Sets the seconds for the specified Date object in local time and returns the new time in milliseconds.

 

setTime(millisecond:Number) : Number

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

 

setUTCDate(date:Number) : Number

Sets the date for the specified Date object in universal time and returns the new time in milliseconds.

 

setUTCFullYear(year:Number, [month:Number], [date:Number]) : Number

Sets the year for the specified Date object (my_date) in universal time and returns the new time in milliseconds.

 

setUTCHours(hour:Number, [minute:Number], [second:Number], [millisecond:Number]) : Number

Sets the hour for the specified Date object in universal time and returns the new time in milliseconds.

 

setUTCMilliseconds(millisecond:Number) : Number

Sets the milliseconds for the specified Date object in universal time and returns the new time in milliseconds.

 

setUTCMinutes(minute:Number, [second:Number], [millisecond:Number]) : Number

Sets the minute for the specified Date object in universal time and returns the new time in milliseconds.

 

setUTCMonth(month:Number, [date:Number]) : Number

Sets the month, and optionally the day, for the specified Date object in universal time and returns the new time in milliseconds.

 

setUTCSeconds(second:Number, [millisecond:Number]) : Number

Sets the seconds for the specified Date object in universal time and returns the new time in milliseconds.

 

setYear(year:Number) : Number

Sets the year for the specified Date object in local time and returns the new time in milliseconds.

 

toString() : String

Returns a string value for the specified date object in a readable format.

static

UTC(year:Number, month:Number, [date:Number], [hour:Number], [minute:Number], [second:Number], [millisecond:Number]) : Number

Returns the number of milliseconds between midnight on January 1, 1970, universal time, and the time specified in the parameters.

 

valueOf() : Number

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


Methods inherited from class Object

addProperty (Object.addProperty method), hasOwnProperty (Object.hasOwnProperty method), isPropertyEnumerable (Object.isPropertyEnumerable method), isPrototypeOf (Object.isPrototypeOf method), registerClass (Object.registerClass method), toString (Object.toString method), unwatch (Object.unwatch method), valueOf (Object.valueOf method), watch (Object.watch method)


Date constructor

public Date([yearOrTimevalue:Number], [month:Number], [date:Number],   [hour:Number], [minute:Number], [second:Number], [millisecond:Number])

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. Alternatively, you can pass a single value to the Date() constructor that indicates a time value based on the number of milliseconds since January 1, 1970 0:00:000 GMT. Or you can specify no parameters, and the Date() date object is assigned the current date and time.

For example, this code shows several different ways to create a Date object:

var d1:Date = new Date(); var d3:Date = new Date(2000, 0, 1); var d4:Date = new Date(65, 2, 6, 9, 30, 15, 0); var d5:Date = new Date(-14159025000);

In the first line of code, a Date object is set to the time when the assignment statement is run.

In the second line, a Date object is created with year, month, and date parameters passed to it, resulting in the time 0:00:00 GMT January 1, 2000.

In the third line, a Date object is created with year, month, and date parameters passed to it, resulting in the time 09:30:15 GMT (+ 0 milliseconds) March 6, 1965. Note that since the year parameter is specified as a two-digit integer, it is interpreted as 1965.

In the fourth line, only one parameter is passed, which is a time value representing the number of milliseconds before or after 0:00:00 GMT January 1, 1970; since the value is negative, it represents a time before 0:00:00 GMT January 1, 1970, and in this case the time is 02:56:15 GMT July, 21 1969.

Availability: ActionScript 1.0; Flash Player 5

Parameters

yearOrTimevalue:Number [optional] - 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 [optional] - An integer from 0 (January) to 11 (December).

date:Number [optional] - An integer from 1 to 31.

hour:Number [optional] - An integer from 0 (midnight) to 23 (11 p.m.).

minute:Number [optional] - An integer from 0 to 59.

second:Number [optional] - An integer from 0 to 59.

millisecond:Number [optional] - An integer from 0 to 999 of milliseconds.

Example

The following example retrieves the current date and time:

var now_date:Date = new Date();

The following example creates a new Date object for Mary's birthday, August 12, 1974 (because the month parameter is zero-based, the example uses 7 for the month, not 8):

var maryBirthday:Date = new Date (74, 7, 12);

The following example creates a new Date object and concatenates the returned values of Date.getMonth(), Date.getDate(), and Date.getFullYear():

var today_date:Date = new Date(); var date_str:String = ((today_date.getMonth()+1)+"/   "+today_date.getDate()+"/"+today_date.getFullYear()); trace(date_str); // displays current date in United States date format

See also

getMonth (Date.getMonth method), getDate (Date.getDate method), getFullYear (Date.getFullYear method)

getDate (Date.getDate method)

public getDate() : Number

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

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example creates a new Date object and concatenates the returned values of Date.getMonth(), Date.getDate(), and Date.getFullYear():

var today_date:Date = new Date(); var date_str:String = (today_date.getDate()+"/   "+(today_date.getMonth()+1)+"/"+today_date.getFullYear()); trace(date_str); // displays current date in United States date format

See also

getMonth (Date.getMonth method), getFullYear (Date.getFullYear method)

getDay (Date.getDay method)

public getDay() : Number

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

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer representing the day of the week.

Example

The following example creates a new Date object and uses getday() to determine the current day of the week:

var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday",   "Wednesday", "Thursday", "Friday", "Saturday"); var today_date:Date = new Date(); var day_str:String = dayOfWeek_array[today_date.getDay()]; trace("Today is "+day_str);

getFullYear (Date.getFullYear method)

public getFullYear() : Number

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

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer representing the year.

Example

The following example uses the constructor to create a Date object. The trace statement shows the value returned by the getFullYear() method.

var my_date:Date = new Date(); trace(my_date.getYear()); // displays 104 trace(my_date.getFullYear()); // displays current year

getHours (Date.getHours method)

public getHours() : Number

Returns the hour (an integer from 0 to 23) of the specified Date object, according to local time. Local time is determined by the operating system on which Flash Player is running.

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example uses the constructor to create a Date object based on the current time and uses the getHours() method to display hour values from that object:

var my_date:Date = new Date(); trace(my_date.getHours()); var my_date:Date = new Date(); var hourObj:Object = getHoursAmPm(my_date.getHours()); trace(hourObj.hours); trace(hourObj.ampm); function getHoursAmPm(hour24:Number):Object {   var returnObj:Object = new Object();   returnObj.ampm = (hour24<12) ? "AM" : "PM";   var hour12:Number = hour24%12;   if (hour12 == 0) {   hour12 = 12;   }   returnObj.hours = hour12;   return returnObj; }

getMilliseconds (Date.getMilliseconds method)

public getMilliseconds() : Number

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

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example uses the constructor to create a Date object based on the current time and uses the getMilliseconds() method to return the milliseconds value from that object:

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

getMinutes (Date.getMinutes method)

public getMinutes() : Number

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

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example uses the constructor to create a Date object based on the current time, and uses the getMinutes() method to return the minutes value from that object:

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

getMonth (Date.getMonth method)

public getMonth() : Number

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

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example uses the constructor to create a Date object based on the current time and uses the getMonth() method to return the month value from that object:

var my_date:Date = new Date(); trace(my_date.getMonth());

The following example uses the constructor to create a Date object based on the current time and uses the getMonth() method to display the current month as a numeric value, and display the name of the month.

var my_date:Date = new Date(); trace(my_date.getMonth()); trace(getMonthAsString(my_date.getMonth())); function getMonthAsString(month:Number):String {   var monthNames_array:Array = new Array("January", "February", "March",   "April", "May", "June", "July", "August", "September", "October",   "November", "December");   return monthNames_array[month]; }

getSeconds (Date.getSeconds method)

public getSeconds() : Number

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

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example uses the constructor to create a Date object based on the current time and uses the getSeconds() method to return the seconds value from that object:

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

getTime (Date.getTime method)

public getTime() : Number

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

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example uses the constructor to create a Date object based on the current time, and uses the getTime() method to return the number of milliseconds since midnight January 1, 1970:

var my_date:Date = new Date(); trace(my_date.getTime());

getTimezoneOffset (Date.getTimezoneOffset method)

public getTimezoneOffset() : Number

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

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example returns the difference between the local daylight saving time for San Francisco and universal time. Daylight saving time is factored into the returned result only if the date defined in the Date object occurs during daylight saving time. The output in this example is 420 minutes and displays in the Output panel (7 hours * 60 minutes/hour = 420 minutes). This example is Pacific Daylight Time (PDT, GMT-0700). The result varies depending on location and time of year.

var my_date:Date = new Date(); trace(my_date.getTimezoneOffset());

getUTCDate (Date.getUTCDate method)

public getUTCDate() : Number

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

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example creates a new Date object and uses Date.getUTCDate() and Date.getDate(). The value returned by Date.getUTCDate() can differ from the value returned by Date.getDate(), depending on the relationship between your local time zone and universal time.

var my_date:Date = new Date(2004,8,25); trace(my_date.getUTCDate()); // output: 25

See also

getDate (Date.getDate method)

getUTCDay (Date.getUTCDay method)

public getUTCDay() : Number

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

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example creates a new Date object and uses Date.getUTCDay() and Date.getDay(). The value returned by Date.getUTCDay() can differ from the value returned by Date.getDay(), depending on the relationship between your local time zone and universal time.

var today_date:Date = new Date(); trace(today_date.getDay()); // output will be based on local timezone trace(today_date.getUTCDay()); // output will equal getDay() plus or minus   one

See also

getDay (Date.getDay method)

getUTCFullYear (Date.getUTCFullYear method)

public getUTCFullYear() : Number

Returns the four-digit year of the specified Date object, according to universal time.

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example creates a new Date object and uses Date.getUTCFullYear() and Date.getFullYear(). The value returned by Date.getUTCFullYear() may differ from the value returned by Date.getFullYear() if today's date is December 31 or January 1, depending on the relationship between your local time zone and universal time.

var today_date:Date = new Date(); trace(today_date.getFullYear()); // display based on local timezone trace(today_date.getUTCFullYear()); // displays getYear() plus or minus 1

See also

getFullYear (Date.getFullYear method)

getUTCHours (Date.getUTCHours method)

public getUTCHours() : Number

Returns the hour (an integer from 0 to 23) of the specified Date object, according to universal time.

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example creates a new Date object and uses Date.getUTCHours() and Date.getHours(). The value returned by Date.getUTCHours() may differ from the value returned by Date.getHours(), depending on the relationship between your local time zone and universal time.

var today_date:Date = new Date(); trace(today_date.getHours()); // display based on local timezone trace(today_date.getUTCHours()); // display equals getHours() plus or minus 12

See also

getHours (Date.getHours method)

getUTCMilliseconds (Date.getUTCMilliseconds method)

public getUTCMilliseconds() : Number

Returns the milliseconds (an integer from 0 to 999) of the specified Date object, according to universal time.

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example creates a new Date object and uses getUTCMilliseconds() to return the milliseconds value from the Date object.

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

getUTCMinutes (Date.getUTCMinutes method)

public getUTCMinutes() : Number

Returns the minutes (an integer from 0 to 59) of the specified Date object, according to universal time.

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example creates a new Date object and uses getUTCMinutes() to return the minutes value from the Date object:

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

getUTCMonth (Date.getUTCMonth method)

public getUTCMonth() : Number

Returns the month (0 [January] to 11 [December]) of the specified Date object, according to universal time.

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example creates a new Date object and uses Date.getUTCMonth() and Date.getMonth(). The value returned by Date.getUTCMonth() can differ from the value returned by Date.getMonth() if today's date is the first or last day of a month, depending on the relationship between your local time zone and universal time.

var today_date:Date = new Date(); trace(today_date.getMonth()); // output based on local timezone trace(today_date.getUTCMonth()); // output equals getMonth() plus or minus   1

See also

getMonth (Date.getMonth method)

getUTCSeconds (Date.getUTCSeconds method)

public getUTCSeconds() : Number

Returns the seconds (an integer from 0 to 59) of the specified Date object, according to universal time.

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example creates a new Date object and uses getUTCSeconds() to return the seconds value from the Date object:

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

getUTCYear (Date.getUTCYear method)

public getUTCYear() : Number

Returns the year of this Date according to universal time (UTC). The year is the full year minus 1900. For example, the year 2000 is represented as 100.

Availability: ActionScript 1.0; Flash Player 8

Returns

Number - An integer.

Example

The following example creates a new Date object and uses Date.getUTCFullYear() and Date.getFullYear(). The value returned by Date.getUTCFullYear() may differ from the value returned by Date.getFullYear() if today's date is December 31 or January 1, depending on the relationship between your local time zone and universal time.

var today_date:Date = new Date(); trace(today_date.getFullYear()); // display based on local timezone trace(today_date.getUTCFullYear()); // displays getYear() plus or minus 1

getYear (Date.getYear method)

public getYear() : Number

Returns the year of the specified Date object, according to local time. Local time is determined by the operating system on which Flash Player is running. The year is the full year minus 1900. For example, the year 2000 is represented as 100.

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - An integer.

Example

The following example creates a Date object with the month and year set to May 2004. The Date.getYear() method returns 104, and Date.getFullYear() returns 2004:

var today_date:Date = new Date(2004,4); trace(today_date.getYear()); // output: 104 trace(today_date.getFullYear()); // output: 2004

See also

getFullYear (Date.getFullYear method)

setDate (Date.setDate method)

public setDate(date:Number) : Number

Sets the day of the month for the specified Date object, according to local time, and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running.

Availability: ActionScript 1.0; Flash Player 5

Parameters

date:Number - An integer from 1 to 31.

Returns

Number - An integer.

Example

The following example initially creates a new Date object, setting the date to May 15, 2004, and uses Date.setDate() to change the date to May 25, 2004:

var today_date:Date = new Date(2004,4,15); trace(today_date.getDate()); //displays 15 today_date.setDate(25); trace(today_date.getDate()); //displays 25

setFullYear (Date.setFullYear method)

public setFullYear(year:Number, [month:Number], [date:Number]) : Number

Sets the year of the specified Date object, according to local time and returns the new time in milliseconds. If the month and date 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 specified Date object 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.

Availability: ActionScript 1.0; Flash Player 5

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 [optional] - An integer from 0 (January) to 11 (December). If you omit this parameter, the month field of the specified Date object will not be modified.

date:Number [optional] - A number from 1 to 31. If you omit this parameter, the date field of the specified Date object will not be modified.

Returns

Number - An integer.

Example

The following example initially creates a new Date object, setting the date to May 15, 2004, and uses Date.setFullYear() to change the date to May 15, 2002:

var my_date:Date = new Date(2004,4,15); trace(my_date.getFullYear()); //output: 2004 my_date.setFullYear(2002); trace(my_date.getFullYear()); //output: 2002

See also

getUTCDay (Date.getUTCDay method), getDay (Date.getDay method)

setHours (Date.setHours method)

public setHours(hour:Number) : Number

Sets the hours for the specified Date object according to local time and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running.

Availability: ActionScript 1.0; Flash Player 5

Parameters

hour:Number - An integer from 0 (midnight) to 23 (11 p.m.).

Returns

Number - An integer.

Example

The following example initially creates a new Date object, setting the time and date to 8:00 a.m. on May 15, 2004, and uses Date.setHours() to change the time to 4:00 p.m.:

var my_date:Date = new Date(2004,4,15,8); trace(my_date.getHours()); // output: 8 my_date.setHours(16); trace(my_date.getHours()); // output: 16

setMilliseconds (Date.setMilliseconds method)

public setMilliseconds(millisecond:Number) : Number

Sets the milliseconds for the specified Date object according to local time and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running.

Availability: ActionScript 1.0; Flash Player 5

Parameters

millisecond:Number - An integer from 0 to 999.

Returns

Number - An integer.

Example

The following example initially creates a new Date object, setting the date to 8:30 a.m. on May 15, 2004 with the milliseconds value set to 250, and then uses Date.setMilliseconds() to change the milliseconds value to 575:

var my_date:Date = new Date(2004,4,15,8,30,0,250); trace(my_date.getMilliseconds()); // output: 250 my_date.setMilliseconds(575); trace(my_date.getMilliseconds()); // output: 575

setMinutes (Date.setMinutes method)

public setMinutes(minute:Number) : Number

Sets the minutes for a specified Date object according to local time and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running.

Availability: ActionScript 1.0; Flash Player 5

Parameters

minute:Number - An integer from 0 to 59.

Returns

Number - An integer.

Example

The following example initially creates a new Date object, setting the time and date to 8:00 a.m. on May 15, 2004, and then uses Date.setMinutes() to change the time to 8:30 a.m.:

var my_date:Date = new Date(2004,4,15,8,0); trace(my_date.getMinutes()); // output: 0 my_date.setMinutes(30); trace(my_date.getMinutes()); // output: 30

setMonth (Date.setMonth method)

public setMonth(month:Number, [date:Number]) : Number

Sets the month for the specified Date object in local time and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running.

Availability: ActionScript 1.0; Flash Player 5

Parameters

month:Number - An integer from 0 (January) to 11 (December).

date:Number [optional] - An integer from 1 to 31. If you omit this parameter, the date field of the specified Date object will not be modified.

Returns

Number - An integer.

Example

The following example initially creates a new Date object, setting the date to May 15, 2004, and uses Date.setMonth() to change the date to June 15, 2004:

var my_date:Date = new Date(2004,4,15); trace(my_date.getMonth()); //output: 4 my_date.setMonth(5); trace(my_date.getMonth()); //output: 5

setSeconds (Date.setSeconds method)

public setSeconds(second:Number) : Number

Sets the seconds for the specified Date object in local time and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running.

Availability: ActionScript 1.0; Flash Player 5

Parameters

second:Number - An integer from 0 to 59.

Returns

Number - An integer.

Example

The following example initially creates a new Date object, setting the time and date to 8:00:00 a.m. on May 15, 2004, and uses Date.setSeconds() to change the time to 8:00:45 a.m.:

var my_date:Date = new Date(2004,4,15,8,0,0); trace(my_date.getSeconds()); // output: 0 my_date.setSeconds(45); trace(my_date.getSeconds()); // output: 45

setTime (Date.setTime method)

public setTime(millisecond:Number) : Number

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

Availability: ActionScript 1.0; Flash Player 5

Parameters

millisecond:Number - A number; an integer value where 0 is midnight on January 1, universal time.

Returns

Number - An integer.

Example

The following example initially creates a new Date object, setting the time and date to 8:00 a.m. on May 15, 2004, and uses Date.setTime() to change the time to 8:30 a.m.:

var my_date:Date = new Date(2004,4,15,8,0,0); var myDate_num:Number = my_date.getTime(); // convert my_date to   milliseconds myDate_num += 30 * 60 * 1000; // add 30 minutes in milliseconds my_date.setTime(myDate_num); // set my_date Date object 30 minutes forward trace(my_date.getFullYear()); // output: 2004 trace(my_date.getMonth()); // output: 4 trace(my_date.getDate()); // output: 15 trace(my_date.getHours()); // output: 8 trace(my_date.getMinutes()); // output: 30

setUTCDate (Date.setUTCDate method)

public setUTCDate(date:Number) : Number

Sets the date for the specified Date object in universal time and returns the new time in milliseconds. Calling this method does not modify the other fields of the specified Date object, 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.

Availability: ActionScript 1.0; Flash Player 5

Parameters

date:Number - A number; an integer from 1 to 31.

Returns

Number - An integer.

Example

The following example initially creates a new Date object with today's date, uses Date.setUTCDate() to change the date value to 10, and changes it again to 25:

var my_date:Date = new Date(); my_date.setUTCDate(10); trace(my_date.getUTCDate()); // output: 10 my_date.setUTCDate(25); trace(my_date.getUTCDate()); // output: 25

See also

getUTCDay (Date.getUTCDay method), getDay (Date.getDay method)

setUTCFullYear (Date.setUTCFullYear method)

public setUTCFullYear(year:Number, [month:Number], [date:Number]) : Number

Sets the year for the specified Date object (my_date) in universal time and returns the new time in milliseconds.

Optionally, this method can also set the month and date represented by the specified Date object. Calling this method does not modify the other fields of the specified Date object, 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.

Availability: ActionScript 1.0; Flash Player 5

Parameters

year:Number - An integer that represents the year specified as a full four-digit year, such as 2000.

month:Number [optional] - An integer from 0 (January) to 11 (December). If you omit this parameter, the month field of the specified Date object will not be modified.

date:Number [optional] - An integer from 1 to 31. If you omit this parameter, the date field of the specified Date object will not be modified.

Returns

Number - An integer.

Example

The following example initially creates a new Date object with today's date, uses Date.setUTCFullYear() to change the year value to 2001, and changes the date to May 25, 1995:

var my_date:Date = new Date(); my_date.setUTCFullYear(2001); trace(my_date.getUTCFullYear()); // output: 2001 my_date.setUTCFullYear(1995, 4, 25); trace(my_date.getUTCFullYear()); // output: 1995 trace(my_date.getUTCMonth()); // output: 4 trace(my_date.getUTCDate()); // output: 25

See also

getUTCDay (Date.getUTCDay method), getDay (Date.getDay method)

setUTCHours (Date.setUTCHours method)

public setUTCHours(hour:Number, [minute:Number], [second:Number],   [millisecond:Number]) : Number

Sets the hour for the specified Date object in universal time and returns the new time in milliseconds.

Availability: ActionScript 1.0; Flash Player 5

Parameters

hour:Number - A number; an integer from 0 (midnight) to 23 (11 p.m.).

minute:Number [optional] - A number; an integer from 0 to 59. If you omit this parameter, the minutes field of the specified Date object will not be modified.

second:Number [optional] - A number; an integer from 0 to 59. If you omit this parameter, the seconds field of the specified Date object will not be modified.

millisecond:Number [optional] - A number; an integer from 0 to 999. If you omit this parameter, the milliseconds field of the specified Date object will not be modified.

Returns

Number - An integer.

Example

The following example initially creates a new Date object with today's date, uses Date.setUTCHours() to change the time to 8:30 a.m., and changes the time again to 5:30:47 p.m.:

var my_date:Date = new Date(); my_date.setUTCHours(8,30); trace(my_date.getUTCHours()); // output: 8 trace(my_date.getUTCMinutes()); // output: 30 my_date.setUTCHours(17,30,47); trace(my_date.getUTCHours()); // output: 17 trace(my_date.getUTCMinutes()); // output: 30 trace(my_date.getUTCSeconds()); // output: 47

setUTCMilliseconds (Date.setUTCMilliseconds method)

public setUTCMilliseconds(millisecond:Number) : Number

Sets the milliseconds for the specified Date object in universal time and returns the new time in milliseconds.

Availability: ActionScript 1.0; Flash Player 5

Parameters

millisecond:Number - An integer from 0 to 999.

Returns

Number - An integer.

Example

The following example initially creates a new Date object, setting the date to 8:30 a.m. on May 15, 2004 with the milliseconds value set to 250, and uses Date.setUTCMilliseconds() to change the milliseconds value to 575:

var my_date:Date = new Date(2004,4,15,8,30,0,250); trace(my_date.getUTCMilliseconds()); // output: 250 my_date.setUTCMilliseconds(575); trace(my_date.getUTCMilliseconds()); // output: 575

setUTCMinutes (Date.setUTCMinutes method)

public setUTCMinutes(minute:Number, [second:Number], [millisecond:Number])   : Number

Sets the minute for the specified Date object in universal time and returns the new time in milliseconds.

Availability: ActionScript 1.0; Flash Player 5

Parameters

minute:Number - An integer from 0 to 59.

second:Number [optional] - An integer from 0 to 59. If you omit this parameter, the seconds field of the specified Date object will not be modified.

millisecond:Number [optional] - An integer from 0 to 999. If you omit this parameter, the milliseconds field of the specified Date object will not be modified.

Returns

Number - An integer.

Example

The following example initially creates a new Date object, setting the time and date to 8:00 a.m. on May 15, 2004, and uses Date.setUTCMinutes() to change the time to 8:30 a.m.:

var my_date:Date = new Date(2004,4,15,8,0); trace(my_date.getUTCMinutes()); // output: 0 my_date.setUTCMinutes(30); trace(my_date.getUTCMinutes()); // output: 30

setUTCMonth (Date.setUTCMonth method)

public setUTCMonth(month:Number, [date:Number]) : Number

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

Availability: ActionScript 1.0; Flash Player 5

Parameters

month:Number - An integer from 0 (January) to 11 (December).

date:Number [optional] - An integer from 1 to 31. If you omit this parameter, the date field of the specified Date object will not be modified.

Returns

Number - An integer.

Example

The following example initially creates a new Date object, setting the date to May 15, 2004, and uses Date.setMonth() to change the date to June 15, 2004:

var today_date:Date = new Date(2004,4,15); trace(today_date.getUTCMonth()); // output: 4 today_date.setUTCMonth(5); trace(today_date.getUTCMonth()); // output: 5

See also

getUTCDay (Date.getUTCDay method), getDay (Date.getDay method)

setUTCSeconds (Date.setUTCSeconds method)

public setUTCSeconds(second:Number, [millisecond:Number]) : Number

Sets the seconds for the specified Date object in universal time and returns the new time in milliseconds.

Availability: ActionScript 1.0; Flash Player 5

Parameters

second:Number - An integer from 0 to 59.

millisecond:Number [optional] - An integer from 0 to 999. If you omit this parameter, the milliseconds field of the specified Date object will not be modified.

Returns

Number - An integer.

Example

The following example initially creates a new Date object, setting the time and date to 8:00:00 a.m. on May 15, 2004, and uses Date.setSeconds() to change the time to 8:30:45 a.m.:

var my_date:Date = new Date(2004,4,15,8,0,0); trace(my_date.getUTCSeconds()); // output: 0 my_date.setUTCSeconds(45); trace(my_date.getUTCSeconds()); // output: 45

setYear (Date.setYear method)

public setYear(year:Number) : Number

Sets the year for the specified Date object in local time and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running.

Availability: ActionScript 1.0; Flash Player 5

Parameters

year:Number - A number that represents the year. If year is an integer between 0 and 99, setYear sets the year at 1900 + year; otherwise, the year is the value of the year parameter.

Returns

Number - An integer.

Example

The following example creates a new Date object with the date set to May 25, 2004, uses setYear() to change the year to 1999, and changes the year to 2003:

var my_date:Date = new Date(2004,4,25); trace(my_date.getYear()); // output: 104 trace(my_date.getFullYear()); // output: 2004 my_date.setYear(99); trace(my_date.getYear()); // output: 99 trace(my_date.getFullYear()); // output: 1999 my_date.setYear(2003); trace(my_date.getYear()); // output: 103 trace(my_date.getFullYear()); // output: 2003

toString (Date.toString method)

public toString() : String

Returns a string value for the specified date object in a readable format.

Availability: ActionScript 1.0; Flash Player 5

Returns

String - A string.

Example

The following example returns the information in the dateOfBirth_date Date object as a string. The output from the trace statements are in local time and vary accordingly. For Pacific Daylight Time the output is seven hours earlier than universal time: Mon Aug 12 18:15:00 GMT-0700 1974.

var dateOfBirth_date:Date = new Date(74, 7, 12, 18, 15); trace (dateOfBirth_date); trace (dateOfBirth_date.toString());

UTC (Date.UTC method)

public static UTC(year:Number, month:Number, [date:Number], [hour:Number],   [minute:Number], [second:Number], [millisecond:Number]) : Number

Returns the number of milliseconds between midnight on January 1, 1970, universal time, and the time specified in the parameters. This is a static method that is invoked through the Date object constructor, not through a specific Date object. This method lets you create a Date object that assumes universal time, whereas the Date constructor assumes local time.

Availability: ActionScript 1.0; Flash Player 5

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 [optional] - An integer from 1 to 31.

hour:Number [optional] - An integer from 0 (midnight) to 23 (11 p.m.).

minute:Number [optional] - An integer from 0 to 59.

second:Number [optional] - An integer from 0 to 59.

millisecond:Number [optional] - An integer from 0 to 999.

Returns

Number - An integer.

Example

The following example creates a new maryBirthday_date Date object defined in universal time. This is the universal time variation of the example used for the new Date constructor method. The output is in local time and varies accordingly. For Pacific Daylight Time the output is seven hours earlier than UTC: Sun Aug 11 17:00:00 GMT-0700 1974.

var maryBirthday_date:Date = new Date(Date.UTC(1974, 7, 12)); trace(maryBirthday_date);

valueOf (Date.valueOf method)

public valueOf() : Number

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

Availability: ActionScript 1.0; Flash Player 5

Returns

Number - The number of milliseconds.



ActionScript 2.0 Language Reference for Macromedia Flash 8
ActionScript 2.0 Language Reference for Macromedia Flash 8
ISBN: 0321384040
EAN: 2147483647
Year: 2004
Pages: 113

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net