Be a Supporter!

AS: Date Object

  • 2,505 Views
  • 13 Replies
New Topic Respond to this Topic
GuyWithHisComp
GuyWithHisComp
  • Member since: Nov. 10, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
AS: Date Object Jan. 18th, 2006 @ 02:02 PM Reply

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
Claxor
Claxor
  • Member since: Oct. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Date Object Jan. 19th, 2006 @ 11:42 AM Reply

Ima add two methods:

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


BBS Signature
T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Date Object Jan. 19th, 2006 @ 11:44 AM Reply

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

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

wtf!? serious?

strange...

Claxor
Claxor
  • Member since: Oct. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Date Object Jan. 19th, 2006 @ 11:49 AM Reply

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
GuyWithHisComp
GuyWithHisComp
  • Member since: Nov. 10, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to AS: Date Object Jan. 19th, 2006 @ 11:49 AM Reply

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
Claxor
Claxor
  • Member since: Oct. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Date Object Jan. 19th, 2006 @ 11:54 AM Reply

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
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Date Object Jan. 19th, 2006 @ 12:54 PM Reply

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
Claxor
Claxor
  • Member since: Oct. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Date Object Jan. 19th, 2006 @ 01:01 PM Reply

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
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Date Object Jan. 19th, 2006 @ 01:06 PM Reply

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

Bankay
Bankay
  • Member since: Mar. 29, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS: Date Object Mar. 30th, 2006 @ 03:22 PM Reply

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

Bankay
Bankay
  • Member since: Mar. 29, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS: Date Object Mar. 30th, 2006 @ 03:27 PM Reply

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 .

Bankay
Bankay
  • Member since: Mar. 29, 2006
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS: Date Object Mar. 30th, 2006 @ 03:29 PM Reply

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

snuffyindustries
snuffyindustries
  • Member since: Mar. 22, 2007
  • Offline.
Forum Stats
Member
Level 13
Programmer
Response to AS: Date Object Sep. 2nd, 2007 @ 05:18 PM Reply

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
kanef
kanef
  • Member since: Nov. 2, 2008
  • Offline.
Forum Stats
Member
Level 13
Artist
Response to AS: Date Object Apr. 5th, 2009 @ 08:57 AM Reply

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


comment pls - plug.dj
sevkitty.com forum - last.fm
D - ńęwgróuńdśęś ręśidęńt pątrićiąń

BBS Signature