Server Time
Yandex Games SDK allows you to get time synchronized with the server. This method is useful for:
- Protection against cheating: users won't be able to affect game processes by changing the time on their device.
- Game events: you can add activities and rewards for which a trusted source of time is important, for example: daily or weekly bonuses, seasonal events, and quests.
ysdk.serverTime()
This method returns a timestamp
, the server time in milliseconds, the same for all devices. It is similar to Date.now()
in the format of the result, however, the latter returns the user's device time, which may differ from server time and is not protected against cheating by players. The ysdk.serverTime()
method cannot be overridden or modified through code, making it more reliable.
Call it every time you need to get the current time.
const ysdk = await YaGames.init();
// Returns time in ms, synchronized with the server.
ysdk.serverTime(); // For example, 1720613073778.
// Call it again after some time.
ysdk.serverTime(); // For example, 1720613132635.
YaGames.init().then(ysdk => {
// Returns time in ms, synchronized with the server.
ysdk.serverTime(); // For example, 1720613073778.
// Some time later, call it again.
ysdk.serverTime(); // For example, 1720613132635.
});
Note
Our support team can help publish finished games on Yandex Games. If you have any questions about development or testing, ask them in the Discord channel.
If you are facing an issue or have a question regarding the use of Yandex Games SDK, please contact support: