question

Talha avatar image
Talha asked

GetTime Function in cloudscript

how does the getTime function work in cloudscript?

this is how we are doing it and what we get in return is somwhat borderline weird. :P

15116112231.232 type stuff. What does that mean? how do we use it to our advantage? like how do we take out the time out of it?

var now= new Date();

var check= now.getTime()/1000;

return check;

apisCloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

getTime is a JavaScript method as CloudScript is based on JavaScript V8 engine. The method returns the number of milliseconds since 1970/01/01:

There are 2 simple way in Cloud Script to get time. First is to use JS built-in method, you may refer to https://www.w3schools.com/jsref/jsref_gettime.asp, next is to call PlayFab API GetTime via:

var mytime =server.GetTime({});

Log.info(mytime.Time);
7 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Talha avatar image Talha commented ·

"This query retrieves the current time from one of the servers in PlayFab. Please note that due to clock drift between servers, there is a potential variance of up to 5 seconds."


so the time variance will always be +- {5 seconds}.what is the worst that can happen if we call the playfab getTime method in cloudscript?

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Talha commented ·

There should be no problem unless you store timestamp for frequent changing data. The result can be confusing because "there is a potential variance of up to 5 seconds". In the normal circumstance, player gets data updated after one round of the game and it should last longer than 5 seconds.

0 Likes 0 ·
Talha avatar image Talha Seth Du ♦ commented ·

this is really good. and the time is universal time so it doesnt matter where the playfab server is located. It will return the Universal time right?

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.