Returns the number of milliseconds since midnight January 1, 1970, universal time, for a Date object. Date[r]
(1)LỚP DATE VÀ TIME
Ngày vấn ñề quan trọng chương trình ứng dụng
Trong Flash AS 3.0 thời gian tính theo đơn vị miligiây theo toạ ñộ thời gian UTC (Coordinated Universal Time ) với mốc thời gian 0h ph giây ngày 01/01/1970
Lấy ngày máy:
// Tạo ñối tượng
var current:Date = new Date( ); trace(“ngày tại:”+current);
kết : ngày Sat Sep 18 15:20:46 GMT+0700 2010 ví dụ :
var d:Date=new Date(); trace(d);
var count:Number=1;
var tTimer:Timer = new Timer(1000, 3);
tTimer.addEventListener(TimerEvent.TIMER, onTimer); tTimer.start( );
function onTimer(event:TimerEvent):void { var d1:Date=new Date();
trace("Goi ham lan "+count.toString()+" sau :"+(d1.time -d.time).toString()+" Miligiay." );
count++; }
Kết quả:
(2)fullYear : lấy năm ñầy ñủ , ví dụ 2010 date: ngày tháng ( từ ñến 31) month: lấy tháng ( từ ñến 11) day: lấy ngày tuần ( từ ñến 6) hours: lấy (từ ñến 23)
minutes : lấy phút (Từ ñến 59) seconds : lấy giây (Từ ñến 59) miliseconds: lấy giây (Từ ñến 999) Ví dụ :
var d:Date=new Date(); trace(d);
trace("d.month:="+d.month ); trace("d.day:="+d.day); trace("d.date:="+d.date);
trace("d.fullYear:="+d.fullYear); trace("d.hours:="+d.hours);
trace("d.minutes :="+d.minutes ); trace("d.seconds:="+d.seconds );
trace("d.milliseconds:="+d.milliseconds); Kết quả:
Sat Sep 18 16:19:35 GMT+0700 2010 d.month:=8
d.day:=6 d.date:=18
(3)d.seconds:=35
d.milliseconds:=812
Ví dụ sau tính thời gian từ chương trình bắt đầu chạy tới thời điểm hện tính theo mili giây: Lưu ý ví dụ có dùng lớp Timer Timer có hay tham số:
Timer(số mili giây chờ);
Timer( số mili giây chờ, số lần ñếm thời gian thực hiện) import flash.display.Sprite;
import flash.text.*;
import flash.utils.Timer ; import flash.events.TimerEvent; import flash.utils.getTimer; var _text:TextField;
var _start:uint;
_start = getTimer( ); _text = new TextField( ); addChild(_text);
var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start( );
function onTimer(event:TimerEvent):void {
_text.text = (getTimer( ) - _start) + " milliseconds"; }
Lưu ý : ðể hiển thị theo , phút ,giây ta phải qui đổi thời gian, Ví dụ sau minh hoạ thời gian đếm ngược có qui đổi thời gian Ở ñây sau hết thời gian ta cho timer dừng lại cách dùng _timer.stop() , khơng timer đếm cho kết thời gian âm
(4)import flash.display.Sprite; import flash.text.*;
import flash.utils.Timer;
import flash.events.TimerEvent; import flash.utils.getTimer;
var _text:TextField; var _timer:Timer; var _start:uint;
var _count:uint = 20;
_start = getTimer( ); _text = new TextField( );
var formatter1:TextFormat = new TextFormat( ); formatter1.font="Arial";
formatter1.size =20;
_text.defaultTextFormat= formatter1; _text.y=stage.stageHeight/2;
_text.x=stage.stageWidth/2; _text.width =150;
addChild(_text);
_timer = new Timer(500);
(5)_timer.start( );
function onTimer(event:TimerEvent):void {
var elapsed:int = Math.round(_count - (getTimer( ) - _start) / 1000);
_text.text = elapsed + " seconds"; if(elapsed < 0) {
_text.text = " -"; _timer.stop( );
} }
Kết :
(6)Thuộc tính
date : Number
The day of the month (an integer from to 31) specified by a Date object according to local time
Date
dateUTC : Number
The day of the month (an integer from to 31) of a Date object according to universal time (UTC)
Date
day : Number
[read-only] The day of the week (0 for Sunday, 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, 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 to 23) of the day portion of a Date object according to local time Date
hoursUTC : Number
The hour (an integer from to 23) of the day of a Date object according to universal time (UTC)
Date
milliseconds : Number
The milliseconds (an integer from to 999) portion of a Date object according to local time Date
millisecondsUTC : Number
The milliseconds (an integer from to 999) portion of a Date object according to universal time (UTC)
Date
minutes : Number
The minutes (an integer from to 59) portion of a Date object according to local time Date
minutesUTC : Number
The minutes (an integer from to 59) portion of a Date object according to universal time (UTC)
Date
month : Number
The month (0 for January, 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 to 59) portion of a Date object according to local time Date
secondsUTC : Number
(7)(UTC)
time : Number
The number of milliseconds since midnight January 1, 1970, universal time, for a Date object
Date
timezoneOffset : Number
[read-only] The difference, in minutes, between universal time (UTC) and the computer's local time
Date Public Methods
Phương thức
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
getDate():Number
Returns the day of the month (an integer from to 31) specified by a Date object according to local time
Date
getDay():Number
Returns the day of the week (0 for Sunday, for Monday, and so on) specified by this Date according to local time
Date
getFullYear():Number
Returns the full year (a four-digit number, such as 2000) of a Date object according to local time
Date
getHours():Number
Returns the hour (an integer from to 23) of the day portion of a Date object according to local time
Date
getMilliseconds():Number
Returns the milliseconds (an integer from to 999) portion of a Date object according to local time
Date
getMinutes():Number
Returns the minutes (an integer from to 59) portion of a Date object according to local time
Date
getMonth():Number
Returns the month (0 for January, for February, and so on) portion of this Date according to local time
Date
getSeconds():Number
Returns the seconds (an integer from to 59) portion of a Date object according to local time
Date
getTime():Number
Returns the number of milliseconds since midnight January 1, 1970, universal time, for a Date object
Date
getTimezoneOffset():Number
Returns the difference, in minutes, between universal time (UTC) and the computer's local time
Date
(8)Returns the day of the month (an integer from to 31) of a Date object, according to universal time (UTC)
getUTCDay():Number
Returns the day of the week (0 for Sunday, for Monday, and so on) of this Date according to universal time (UTC)
Date
getUTCFullYear():Number
Returns the four-digit year of a Date object according to universal time (UTC) Date
getUTCHours():Number
Returns the hour (an integer from to 23) of the day of a Date object according to universal time (UTC)
Date
getUTCMilliseconds():Number
Returns the milliseconds (an integer from to 999) portion of a Date object according to universal time (UTC)
Date
getUTCMinutes():Number
Returns the minutes (an integer from to 59) portion of a Date object according to universal time (UTC)
Date
getUTCMonth():Number
Returns the month (0 [January] to 11 [December]) portion of a Date object according to universal time (UTC)
Date
getUTCSeconds():Number
Returns the seconds (an integer from to 59) portion of a Date object according to universal time (UTC)
Date
hasOwnProperty(name:String):Boolean
Indicates whether an object has a specified property defined Object
isPrototypeOf(theClass:Object):Boolean
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter
Object
parse(date:String):Number
[static] Converts a string representing a date into a number equaling the number of milliseconds elapsed since January 1, 1970, UTC
Date
propertyIsEnumerable(name:String):Boolean
Indicates whether the specified property exists and is enumerable Object
setDate(day:Number):Number
Sets the day of the month, according to local time, and returns the new time in milliseconds Date
setFullYear(year:Number, month:Number, day:Number):Number
Sets the year, according to local time, and returns the new time in milliseconds Date
setHours(hour:Number, minute:Number, second:Number, millisecond:Number):Number
Sets the hour, according to local time, and returns the new time in milliseconds Date
setMilliseconds(millisecond:Number):Number
Sets the milliseconds, according to local time, and returns the new time in milliseconds Date
setMinutes(minute:Number, second:Number, millisecond:Number):Number
Sets the minutes, according to local time, and returns the new time in milliseconds Date
setMonth(month:Number, day:Number):Number
(9)new time in milliseconds
setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void
Sets the availability of a dynamic property for loop operations Object
setSeconds(second:Number, millisecond:Number):Number
Sets the seconds, according to local time, and returns the new time in milliseconds Date
setTime(millisecond:Number):Number
Sets the date in milliseconds since midnight on January 1, 1970, and returns the new time in milliseconds
Date
setUTCDate(day:Number):Number
Sets the day of the month, in universal time (UTC), and returns the new time in milliseconds
Date
setUTCFullYear(year:Number, month:Number, day:Number):Number
Sets the year, in universal time (UTC), and returns the new time in milliseconds Date
setUTCHours(hour:Number, minute:Number, second:Number,
millisecond:Number):Number
Sets the hour, in universal time (UTC), and returns the new time in milliseconds
Date
setUTCMilliseconds(millisecond:Number):Number
Sets the milliseconds, in universal time (UTC), and returns the new time in milliseconds Date
setUTCMinutes(minute:Number, second:Number, millisecond:Number):Number
Sets the minutes, in universal time (UTC), and returns the new time in milliseconds Date
setUTCMonth(month:Number, day:Number):Number
Sets the month, and optionally the day, in universal time(UTC) and returns the new time in milliseconds
Date
setUTCSeconds(second:Number, millisecond:Number):Number
Sets the seconds, and optionally the milliseconds, in universal time (UTC) and returns the new time in milliseconds
Date
toDateString():String
Returns a string representation of the day and date only, and does not include the time or timezone
Date
toLocaleDateString():String
Returns a String representation of the day and date only, and does not include the time or timezone
Date
toLocaleString():String
Returns a String representation of the day, date, time, given in local time Date
toLocaleTimeString():String
Returns a String representation of the time only, and does not include the day, date, year, or timezone
Date
toString():String
Returns a String representation of the day, date, time, and timezone Date
toTimeString():String
Returns a String representation of the time and timezone only, and does not include the day and date
Date
toUTCString():String
(10)
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
valueOf():Number
Returns the number of milliseconds since midnight January 1, 1970, universal time, for a Date object
Date
Ví dụ sau xuất ngày tháng tiếng Việt khơng dáu Muốn có dấu trang viết code ta thay ñổi kiểu gõ TCVN font dạng VNI hổ trợ Unicode
var Thang:Array = new Array("Thang gieng","Thang Hai","Thang Ba", "Thang Tu","Thang Nam","Thang Sau",
"Thang Bay","Thang Tam","Thang Chin",
"Thang Muoi","Thang Muoi mot", "Thang Muoi Hai"); var Thungay:Array = new Array("Chu Nhat","Thu Hai","Thu Ba",
"Thu Tu","Thu Nam","Thu Sau","Thu Bay")
var now:Date = new Date();
trace(Thungay[now.getUTCDay()]+" "+now.getUTCDate() +" "+ Thang[now.getUTCMonth()]+" nam "+
now.getUTCFullYear()); Kết quả:
Thu Bay 18 Thang Chin nam 2010 -
Ví dụ thêm khơng thêm số cách viết phút:
var someday:Date = new Date(2010, 18, 09, 15, 5);
(11)trace(someday.getHours() + ":" + someday.getMinutes());
var gio_cua_may_ban:String = gio_kieu_USA(someday.getHours(), someday.getMinutes());
trace(gio_cua_may_ban);
function gio_kieu_USA(hrs:uint, mins:uint):String { var sang_chieu:String = "PM";
var Phut:String = kieu_hai_so(mins);
if(hrs > 12) { hrs = hrs-12; } else if(hrs == 0) { sang_chieu = "AM"; hrs = 12;
} else if(hrs < 12) { sang_chieu = "AM"; }
return (kieu_hai_so(hrs) + ":" + Phut + " " + sang_chieu); }
function kieu_hai_so(num:uint):String { if(num < 10) {
return ("0" + num); }
(12)Kết quả:
Sat Jul 15:05:00 GMT+0700 2011 15:5