Forum C# Return UTC Date from server?

Return UTC Date from server?

Postby kikurt18 » February 15th, 2012, 7:33 pm

What's the best way to return the server date? I don't want to rely on the client. Thanks in advance.
kikurt18
Paid Member
 
Posts: 9
Joined: April 25th, 2011, 5:34 pm
Location: Vermont, USA

Re: Return UTC Date from server?

Postby Henrik » February 16th, 2012, 11:56 am

Currently, the only way to do that is to have the client join a multiplayer room, and make the serverside code send the time back in a message and then just disconnect the client again.

On the other hand, you could just have the client fetch a webpage which contains the current time in UTC. If you find one, I tried googling for it, but no luck. :)
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Return UTC Date from server?

Postby kikurt18 » February 16th, 2012, 10:27 pm

I found another option for Facebook Apps/Games. Use the "now()" function call in FQL.

For example, use a FQL call such as "SELECT now() FROM user WHERE uid = me();"
The function returns a number of seconds since January 1, 1970. Multiply this number by 1000 to convert to milliseconds so you can use the number properly in AS3. You can then use the Date class to get the date.

EXAMPLE:
var timeSeconds:Number = 1329419055; // this would be the number returned in the FQL query
var currentDate:Date = new Date(timeSeconds * 1000);
trace("Current date = " + (currentDate.getMonth()+1) + "/" + currentDate.getDate() + "/" + currentDate.getFullYear());
kikurt18
Paid Member
 
Posts: 9
Joined: April 25th, 2011, 5:34 pm
Location: Vermont, USA

Re: Return UTC Date from server?

Postby Benjaminsen » March 8th, 2012, 10:17 pm

I think we will build a small extension API for just this type of request. Stay tuned.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark


Return to C#