current time and date?

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

User avatar
goodguy20k
Posts: 71
Joined: 10 Jan 2006, 23:58
Location: Texas, USA
Contact:

current time and date?

Postby goodguy20k » 16 Mar 2006, 22:55

I had to jump through hoops to get a date and time in Flash itself, but now I need to get the date and time in serverside. Is there a function for this in AS (serverside edition) that will work? (I tried copying my code from client side to server and, as I expected, it failed.)
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 17 Mar 2006, 09:34

You can use the Date object. Just like in Flash.

Example:

Code: Select all

var d = new Date();
trace((d.getMonth()+1)+"/"+d.getDate()+"/"+(1900+d.getYear()));


getMonth returns the month number from 0 to 11 (add 1 to get the actual number)

getYear returns the number of years since 1900
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Postby Virusescu » 17 Mar 2006, 09:43

Hello Lapo.
Is this the standard implementation? I mean if I create a new AS1 Date object will it have all the methods associated with his respective flash client Date object? Or is this your implementation on server side and you added just a couple of methods?
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 17 Mar 2006, 09:50

The AS 1.0 engine is based on Mozilla Rhino, which is Ecma-262 compliant. So you will find the same implementation.
I'd recommend to check the Flash help for further help on the Date object

:)
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
goodguy20k
Posts: 71
Joined: 10 Jan 2006, 23:58
Location: Texas, USA
Contact:

Postby goodguy20k » 17 Mar 2006, 14:32

That is a pain. Looks like you copied and pasted my code there, Lapo! Back to error finding... Wish me luck!
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 17 Mar 2006, 14:50

:?: :?: :?:
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
goodguy20k
Posts: 71
Joined: 10 Jan 2006, 23:58
Location: Texas, USA
Contact:

Postby goodguy20k » 17 Mar 2006, 17:03

My code that I had for client side and tried in serverside:

Code: Select all

                  var today_date:Date = new Date();
                  var date_str:String = ((today_date.getHours() + 1) + ":" + (today_date.getMinutes() + 1) + ":" + (today_date.getSeconds() + 1) + " " + (today_date.getMonth() + 1) + "-" + today_date.getDate() + "-" + today_date.getFullYear());
                  res.mydate = date_str;
User avatar
goodguy20k
Posts: 71
Joined: 10 Jan 2006, 23:58
Location: Texas, USA
Contact:

Postby goodguy20k » 17 Mar 2006, 17:05

Outputs this error:

Code: Select all

2006/03/17 11:14:09.270 - [ WARNING ] [id: 12] (JavascriptExtension.logASError): Error in extension [ VIP_login.as ]: missing ; before statement (VIP_login.as#1121) Line: 167
User avatar
goodguy20k
Posts: 71
Joined: 10 Jan 2006, 23:58
Location: Texas, USA
Contact:

Postby goodguy20k » 17 Mar 2006, 17:08

And the answer is, it doesn't like me specifying the variable type in the same format. Had to remove the ":Date" and ":String" in the first two lines. All working now. :)
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 17 Mar 2006, 17:51

Yep, that's AS 1.0, not 2.0 :P
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
goodguy20k
Posts: 71
Joined: 10 Jan 2006, 23:58
Location: Texas, USA
Contact:

Postby goodguy20k » 17 Mar 2006, 18:16

And so have I learned. Thank you again, Lapo.

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 12 guests