00:00
00:00

AS: Date Object

3,213 Views | 12 Replies
New Topic Respond to this Topic

AS: Date Object 2006-01-18 14:02:33


AS:Main

DATE OBJECT

In this tutorial I will show you how to properly use the Date Object.
The Date object is used to get the date with year, months, hours, minutes etc.
You can either set it to GMT (Greenwich Mean Time, or in script called UTC) or set it from the date from your operating system.

The simpliest code for getting the date is

new Date();

Which, for example, could show up as (if in a textbox):
Fri Jan 20 19:28:43 GMT+0100 2006

Below is the order of the parameters in the Date object so you can set them as you like later:
year, month, date, hour, minute, second, millisecond

So if you want a Date object to show the current date as year 1954 and month 5 you'll have to write this:

date = new Date (54, 5);

Remember, if you'll change the year the values 0-99 will show as 1900-1999 otherwise you'll have to write the full, four-digits, code.
And for the months, values are 0-11 and not 1-12. And the hours start at 0-23.

For a simple digital clock you can use this and have a dynamic text box called my_TextField
(See a bigger list below)

my_Date = new Date();
my_TextField = (my_Date.getHours() + ":" + my_Date.getMinutes() + ":" + my_Date.getSeconds());

THE DATE OBJECT GET LIST

getHours()
Used to get the current hours according to the operator.
getUTCHours()
Used to get the current hours according to the GMT time.
getMinutes()
Used to get the current minutes according to the operator.
getUTCMinutes()
Used to get the current minutes according to the GMT time.
getSeconds()
Used to get the current seconds according to the operator.
getUTCSeconds()
Used to get the current seconds according to the GMT time.
getMilliseconds()
Used to get the current milliseconds according to the operator.
getUTCMilliseconds()
Used to get the current milliseconds according to the GMT time.
getFullYear()
Used to get the current year according to the operator.
getUTCFullYear()
Used to get the current year according to the GMT time.
getMonth()
Used to get the current month according to the operator.
getUTCMonth()
Used to get the current month according to the GMT time.
getDate()
Used to get the current date according to the operator.
getUTCDate()
Used to get the current date according to the GMT time.

I think this is everything you need to know, if it's anymore that is missing please tell me.
Oh, and if you want a regular clock instead of a digital I showed above see this tutorial by Glaiel_Gamer:
AS:Clock by Glaiel_Gamer

If there's something you don't understand feel free to ask :)

Thanks for me,
-Snail-


BBS Signature

Response to AS: Date Object 2006-01-19 11:42:38


Ima add two methods:

getTime(); // Returns milliseconds passed since Jan 1 1970
getTimezoneOffset() // Gets the timezone offset (duh)


BBS Signature

Response to AS: Date Object 2006-01-19 11:44:54


At 1/19/06 11:42 AM, Claxor wrote: Ima add two methods:

getTime(); // Returns milliseconds passed since Jan 1 1970

wtf!? serious?

strange...

Response to AS: Date Object 2006-01-19 11:49:02


At 1/19/06 11:44 AM, T-H wrote: wtf!? serious?

strange...

Yeah :P
Good for determining time passed between 2 dates.

var daysPassed:Number = ((((firstDate.getTime()-secondDate.getTime
())/1000)/3600)/24);


BBS Signature

Response to AS: Date Object 2006-01-19 11:49:57


At 1/19/06 11:42 AM, Claxor wrote:ยด
Finally someone who asks something :)

Ima add two methods:

Wha? No questions?! -_-


getTime(); // Returns milliseconds passed since Jan 1 1970

Yeah, I exluded that one because I don't think it's really important :P

getTimezoneOffset() // Gets the timezone offset (duh)

NO SHIT?! oO

oo


BBS Signature

Response to AS: Date Object 2006-01-19 11:54:19


At 1/19/06 11:49 AM, -Snail- wrote: Yeah, I exluded that one because I don't think it's really important :P

Not important!? =0
It's my favourite date method, you just made me sad :'(

getTimezoneOffset() // Gets the timezone offset (duh)
NO SHIT?! oO

Lol...

And to be really annoying:
getYear(); // Returns the year minus 1900


BBS Signature

Response to AS: Date Object 2006-01-19 12:54:09


At 1/19/06 11:49 AM, Claxor wrote:
At 1/19/06 11:44 AM, T-H wrote: wtf!? serious?

strange...
Yeah :P
Good for determining time passed between 2 dates.

Also good for creating a unique number when saving a file or whatever. That's what I've done with my upload page, the numbers at the start of the filename are created with the PHP equivalent of getTime (strtotime("now"))


- - Flash - Music - Images - -

BBS Signature

Response to AS: Date Object 2006-01-19 13:01:50


At 1/19/06 12:54 PM, Denvish wrote: Also good for creating a unique number when saving a file or whatever. That's what I've done with my upload page, the numbers at the start of the filename are created with the PHP equivalent of getTime (strtotime("now"))

Yeah, I usually use it when i wanna reference to a PHP file and keep it from cashing the file, but i add both the time as a date and a random number, like so: "phpfile.php?"+date.getTime()+random(10000
)


BBS Signature

Response to AS: Date Object 2006-01-19 13:06:42


function isAfter(d:Number,m:Number,y:Number):Boolea
n {
var i:Date = new Date();
if (y>i.getFullYear()) {
return true;
}
if (y == i.getFullYear()) {
if (m>(i.getMonth()+1)) {
return true;
}
if (m == (i.getMonth()+1)) {
if (d>= i.getDate()) {
return true;
}
return false;
}
return false;
}
return false;
}

useful function that checks if a date is before or after a certein date you specify

Response to AS: Date Object 2006-03-30 15:22:58


At 1/18/06 02:02 PM, -SNAIL- wrote:
For a simple digital clock you can use this and have a dynamic text box called my_TextField
(See a bigger list below)

my_Date = new Date();
my_TextField = (my_Date.getHours() + ":" + my_Date.getMinutes() + ":" + my_Date.getSeconds());
-Snail-

Well...it dosen't work ... :|

Response to AS: Date Object 2006-03-30 15:27:35


At 3/30/06 03:22 PM, Bankay wrote:
At 1/18/06 02:02 PM, -SNAIL- wrote:
For a simple digital clock you can use this and have a dynamic text box called my_TextField
(See a bigger list below)

my_Date = new Date();
my_TextField = (my_Date.getHours() + ":" + my_Date.getMinutes() + ":" + my_Date.getSeconds());
-Snail-
Well...it dosen't work ... :|

lol ,noob me :P , i put the "my_TextField" in the sentence name ... u didn't specified where ...so i kind'a figured it out after 1 min of the post above ... it work perfectly 10x... i was looking for something like this .

Response to AS: Date Object 2006-03-30 15:29:07


offf ,noob me part 2 ... : / i ment instance name not sentence name ...sry for triple posting but there isn't any edit button : /

Response to AS: Date Object 2007-09-02 17:18:14


Great tutorial. Helped loads, i was problems with displaying time and date correctly.
Anyway i used the below script which you proved, which worked i then added a second keyframe with a gotoAndPlay(1); so it would refresh the seconds, minutes and hours. This worked but i then realized when any of the numbers were below 10 they just showed the one digit ( 09:05 AM would show 9:5 AM).
Is their any way to show a 0 before a digit if it was below 10.
here is the script i used.
Frame 1

my_Date = new Date();
myDIG = (my_Date.getHours() + ":" + my_Date.getMinutes() + ":" + my_Date.getSeconds());

Frame 2
:gotoAndPlay(1);

myDIG being the dynamic text box to display the time.

Thanks for the help and the useful tutorial


BBS Signature