Forum Topic: AS: Date Object

(1,822 views • 13 replies)

This topic is 1 page long.

<< < > >>
None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 1/18/06 02:02 PM

GuyWithHisComp LIGHT LEVEL 27

Sign-Up: 11/10/05

Posts: 4,010

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

None

Claxor

Reply To Post Reply & Quote

Posted at: 1/19/06 11:42 AM

Claxor DARK LEVEL 10

Sign-Up: 10/21/05

Posts: 2,465

Ima add two methods:

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

BBS Signature

None

T-H

Reply To Post Reply & Quote

Posted at: 1/19/06 11:44 AM

T-H LIGHT LEVEL 39

Sign-Up: 01/07/04

Posts: 4,893

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

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

wtf!? serious?

strange...


None

Claxor

Reply To Post Reply & Quote

Posted at: 1/19/06 11:49 AM

Claxor DARK LEVEL 10

Sign-Up: 10/21/05

Posts: 2,465

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

None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 1/19/06 11:49 AM

GuyWithHisComp LIGHT LEVEL 27

Sign-Up: 11/10/05

Posts: 4,010

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

None

Claxor

Reply To Post Reply & Quote

Posted at: 1/19/06 11:54 AM

Claxor DARK LEVEL 10

Sign-Up: 10/21/05

Posts: 2,465

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

None

Denvish

Reply To Post Reply & Quote

Posted at: 1/19/06 12:54 PM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

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

None

Claxor

Reply To Post Reply & Quote

Posted at: 1/19/06 01:01 PM

Claxor DARK LEVEL 10

Sign-Up: 10/21/05

Posts: 2,465

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

None

Inglor

Reply To Post Reply & Quote

Posted at: 1/19/06 01:06 PM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

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


None

Bankay

Reply To Post Reply & Quote

Posted at: 3/30/06 03:22 PM

Bankay NEUTRAL LEVEL 01

Sign-Up: 03/29/06

Posts: 6

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 ... :|


None

Bankay

Reply To Post Reply & Quote

Posted at: 3/30/06 03:27 PM

Bankay NEUTRAL LEVEL 01

Sign-Up: 03/29/06

Posts: 6

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 .


None

Bankay

Reply To Post Reply & Quote

Posted at: 3/30/06 03:29 PM

Bankay NEUTRAL LEVEL 01

Sign-Up: 03/29/06

Posts: 6

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


Resigned

snuffyindustries

Reply To Post Reply & Quote

Posted at: 9/2/07 05:18 PM

snuffyindustries FAB LEVEL 13

Sign-Up: 03/22/07

Posts: 21

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

Questioning

Kane-Animation

Reply To Post Reply & Quote

Posted at: 4/5/09 08:57 AM

Kane-Animation FAB LEVEL 10

Sign-Up: 11/02/08

Posts: 339

What does My_date mean?
(oh and sorry for the bump 0:) )

HI TOMFULP!!! | My sig is a .gif |
My website | My Youtube |
I was popular on this thread! | And this one!

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 07:53 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!